epurdom@stanford.edu
2004-Dec-09 19:28 UTC
[Rd] wishlist -- names gives slotnames (PR#7410)
Full_Name: Elizabeth Purdom Version: 1.9.1 OS: Windows XP Submission from: (NULL) (171.64.102.199) It would be nice if names(obj) would give slot names as well. Since for many people slots are new, the first thing that happens is you try to access what's in them and can't find how to do it. If you don't know that slotNames() exists, it can be very frustrating. Moreover, if you don't even know that the objects has slots (or that such things exist), it's extremely confusing. It just looks like nothing is there (you get NULL). If needed, you could have a message that says that these are slots and should be accessed with "@". Thanks, Elizabeth
maechler@stat.math.ethz.ch
2004-Dec-10 08:55 UTC
[Rd] wishlist -- names gives slotnames (PR#7410)
>>>>> "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
epurdom@stanford.edu
2004-Dec-10 17:49 UTC
[Rd] wishlist -- names gives slotnames (PR#7410)
>Thank you for your thoughts,.. >but > > ``As with everything, use str() ''I agree that there is no substitute for str() for finding out about an object when you're stuck. But I always thought the idea was the user didn't need to know what the object was, the same basic functions gave some kind of reasonable result. So it's counterintuitive to have to learn/find new functions that, at least from the user's point of view, do the same thing.>--- 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 !)I poked around on 2.0.1 and it seemed the same with regard to names(), though I hadn't noticed the new str() functionality for slots. Sorry for posting; I'll avoid it in the future. Thanks, Elizabeth