I am designing a remote procedure protocol for R, which basically performs a
do.call on data and arguments supplied by a client. However, I am
experiencing unfortunate behavior of the do.call function. The function
do.call seems to serialize all objects in the args list, resulting in an
enormous expression, that is then in some way or another returned by many
functions. A short example:
args <- list(data=cars, formula=dist~speed);
do.call("lm",args);
One can see that for this small example, the returned 'call' attribute is
already huge. Another example:
eval(call("cor.test", x=rnorm(100), y=rnorm(100)))
I completely understand why this happens, yet I was wondering if there is an
alternative to call/do.call that constructs the call in an different way so
that the actual call object is somewhat more compact and does not contain
all the data that was involved in the function. For example one that
attaches the args list in an environment and constructs a call that refers
to these objects or something similar.
--
View this message in context: http://r.789695.n4.nabble.com/call-do-call-expression-too-big-tp3574335p3574335.html
Sent from the R devel mailing list archive at Nabble.com.
call / do.call expression too big
5 messages · Henrique Dallazuanna, Jeroen Ooms, Hadley Wickham
Try this: args <- list(data=quote(cars), formula=dist~speed)
On Sat, Jun 4, 2011 at 7:49 PM, Jeroen Ooms <jeroenooms at gmail.com> wrote:
I am designing a remote procedure protocol for R, which basically performs a
do.call on data and arguments supplied by a client. However, I am
experiencing unfortunate behavior of the do.call function. The function
do.call seems to serialize all objects in the args list, resulting in an
enormous expression, that is then in some way or another returned by many
functions. A short example:
args <- list(data=cars, formula=dist~speed);
do.call("lm",args);
One can see that for this small example, the returned 'call' attribute is
already huge. Another example:
eval(call("cor.test", x=rnorm(100), y=rnorm(100)))
I completely understand why this happens, yet I was wondering if there is an
alternative to call/do.call that constructs the call in an different way so
that the actual call object is somewhat more compact and does not contain
all the data that was involved in the function. For example one that
attaches the args list in an environment and constructs a call that refers
to these objects or something similar.
--
View this message in context: http://r.789695.n4.nabble.com/call-do-call-expression-too-big-tp3574335p3574335.html
Sent from the R devel mailing list archive at Nabble.com.
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
I completely understand why this happens, yet I was wondering if there is an alternative to call/do.call that constructs the call in an different way so that the actual call object is somewhat more compact and does not contain all the data that was involved in the function. For example one that attaches the args list in an environment and constructs a call that refers to these objects or something similar.
Like this?
argn <- lapply(names(args), as.name)
names(argn) <- names(args)
call <- as.call(c(list(as.name("lm")), argn))
eval(call, args)
Hadley
Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20110605/5db68efc/attachment.pl>
On Sun, Jun 5, 2011 at 4:25 PM, Jeroen Ooms <jeroen.ooms at stat.ucla.edu> wrote:
argn <- lapply(names(args), as.name)
names(argn) <- names(args)
call <- as.call(c(list(as.name("lm")), argn))
eval(call, args)
Great, almost! Is there any way I can explicitly specify the package of the function in this way? I tried replacing "lm" with "stats::lm" but that did not work.
Hmmm, not sure. Maybe something like: call("::", as.name("stats"),
as.name("lm"))
Hadley
Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/