From maechler at stat.math.ethz.ch  Fri Dec 10 08:55:44 2004
From: maechler at stat.math.ethz.ch (maechler@stat.math.ethz.ch)
Date: Fri Dec 10 08:55:52 2004
Subject: [Rd] wishlist -- names gives slotnames (PR#7410)
Message-ID: <20041210075544.7392C10F39@slim.kubism.ku.dk>

>>>>> "ElizP" == Elizabeth Purdom <epurdom@stanford.edu>
>>>>>     on Thu,  9 Dec 2004 19:28:40 +0100 (CET) writes:

    ElizP> Full_Name: Elizabeth Purdom Version: 1.9.1 OS:
    ElizP> Windows XP Submission from: (NULL) (171.64.102.199)

    ElizP> It would be nice if names(obj) would give slot names
    ElizP> as well. Since for many people slots are new, the
    ElizP> first thing that happens is you try to access what's
    ElizP> in them and can't find how to do it. 

Thank you for your thoughts,..
but

  ``As with everything, use  str() ''   

--- but you need at least R 2.0.0; your R 1.9.1 is too old for
    this (and probably, in general for posting to R-bugs !)

E.g.  
      library(stats4)
      example(mle)
      str(fit2)

gives

   Formal class 'mle' [package "stats4"] with 8 slots
     ..@ call     : language mle(minuslogl = ll2)
     ..@ coef     : Named num [1:2] 3.22 1.12
     .. ..- attr(*, "names")= chr [1:2] "lymax" "lxhalf"
     ..@ fullcoef : Named num [1:2] 3.22 1.12
     .. ..- attr(*, "names")= chr [1:2] "lymax" "lxhalf"

    <.......>

Now if you don't know much about S4 classes, you see the word
"slot" in the first line of str()'s output and
hopefully try

   help(slot)

This will tell you about  slotNames().

    ElizP> If you don't know that slotNames() exists, it can be
    ElizP> very frustrating. Moreover, if you don't even know
    ElizP> that the objects has slots (or that such things
    ElizP> exist), it's extremely confusing. 

I agree that it might be confusing {but do use str() .. }

    ElizP> exist), it's extremely confusing. It just looks like
    ElizP> nothing is there (you get NULL). 

The same happens if you do  length(..) of an S4 object; that
gives 0;  so at least names() and length() are consistent ;-)

I'm not so sure if inames() should be extended to S4 classes
that way;  in any case if it's done, length(<obj>) should also
give the same as  length(names(<obj>)).

I'm CC'ing John Chambers, the masterminder of S4, to make sure we
get his comments on this.

    ElizP> If needed, you could have a message that says that
    ElizP> these are slots and should be accessed with "@".

It seems you are thinking about list()s and their names.
Note that atomic vector have names too and these are not accessed
with "$" either.  So I wouldn't see the need for such a message.

Martin


[Rd] wishlist -- names gives slotnames (PR#7410)
maechler@stat.math.ethz.ch