My thanks to Tony Plate and Bill Dunlap who, between them, mostly resoved my
confusion. It has nothing to do with classes, but rather that:
a) boxplot is not properly documented in the Help file (again, poor
documentation !)
b) I was not smart enough to look at the boxplot generic and see that it
needed an "x" argument and thereby figure out (at least partially) for
myself what the issue was.
Here are the details, synthesized from their two replies.
If z is a data.frame, it already is a list. Therefore, as.list(z) = z . So
if z has 10 named components, so does as.list(z). In other words, as.list()
does nothing here.
However, list(z) is a list with one unnamed component, the list, z.
Now do.call's 2nd argument should be a list.Therefore:
>do.call ('boxplot',z) calls the generic function boxplot, with arguments
the NAMED components of z. None of these components is named 'x', which is
what the generic needs to be supplied, either implicitly or explicitly
(except that it can't be done explicitly -- see below).
However,
>do.call('boxplot',list(z)) calls boxplot with argument one UNNAMED
component, z. Now here's where things get weirder. This is the same as
>boxplot(z) and boxplots the data properly for z a data.frame or a list (as
the default method takes care of lists).
Therefore, one would think that
>boxplot(x=z) would work, but it doesn't -- the error "Error in boxplot: no
data" bubbles up from the Fortran code..
Even cuter,
>boxplot(x=list(),z) or >boxplot(x=1:3,z)
Both produce the plots but then choke while trying to title them and bubble
up interesting Fortran error messages. I can do no better then to quote Bill
Dunlap's reply to this "feature" :
*** BILL DUNLAP REPLY ****
I don't have a good answer for this now, but
boxplot has acted this way since at least Splus3.3.
It looks like if you name the first argument (x=something)
then it throws it away (and complains about "no data")!
It got a little more confused when boxplot was made into
a generic function. Before then it had no x= argument and
now it does.
*************
So that's it for now, folks. None of this is documented, of course
(especially the fact that boxplot() is now a generic), so I am grateful for
Bill's reply. I don't think I would have had a clue otherwise.
Cheers,
Bert Gunter
Biometrics Research RY 70-38
Merck & Company
P.O. Box 2000
Rahway, NJ 07065-0900
Phone: (732) 594-7765
mailto: bert_gunter@merck.com
"The business of the statistician is to catalyze the scientific learning
process." -- George E.P. Box
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may
be confidential, proprietary copyrighted and/or legally privileged, and is
intended solely for the use of the individual or entity named on this message.
If you are not the intended recipient, and have received this message in error,
please immediately return this by e-mail and then delete it.
==============================================================================
|