The second argument to do.call() is a *list of arguments* to the function,
and a data frame is a list. So, when you do do.call('boxplot', dataframe)
or do.call("boxplot", as.list(dataframe)), boxplot gets called with
multiple arguments: the columns of the data frame. But, when you do
do.call("boxplot", list(dataframe)), boxplot gets just one argument: the
dataframe.
Easily verified:
> foo <- function(...) browser()
> do.call("foo", data.frame(a=1:3,b=4:6))
b(foo)> list(...)
$a:
[1] 1 2 3
$b:
[1] 4 5 6
b(foo)> c
NULL
> do.call("foo", as.list(data.frame(a=1:3,b=4:6)))
Called from: foo(a = c(1, 2, 3), b = c(....
b(foo)> list(...)
$a:
[1] 1 2 3
$b:
[1] 4 5 6
b(foo)> c
NULL
> do.call("foo", list(data.frame(a=1:3,b=4:6)))
Called from: foo(structure(.Data = list....
b(foo)> list(...)
[[1]]:
a b
1 1 4
2 2 5
3 3 6
-- Tony Plate
At 12:48 PM 8/27/2002 -0400, you wrote:
Hello all:
I'm stumped. I would appreciate insight on the following: (S-Plus 6.1 under
winnt)
z is a data.frame. The following boxplots the columns:
>boxplot(z)
because boxplot is (now?) a generic with a method for data.frames. However,
not realizing this, I tried an old trick:
>do.call('boxplot',z)
and got an error saying that "argument 'x' is missing with no default."
Same error for >do.call('boxplot',as.list(z)) and
do.call('boxplot',as(z,'list'))
However, even though z is already a list, as manifested by is.list(z) = T,
>do.call('boxplot',list(z))
works!
I would greatly appreciate an explanation of this (to me) puzzling behavior
(new classes, scope??). Certainly seems to violate the maxim of least
surprise in software design.
Thanks.
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.
==============================================================================
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|