[R] match.call() and do.call()
Peter Perkins
pperkins at ucsd.edu
Sat Feb 10 08:11:46 CET 2001
hi all -
i have a function that needs to call glm() with a weights argument that
includes a variable whose name comes from the caller. so instead of:
fit <- glm(formula, poisson(), data, weights = 1-z, ...),
i do something like this:
fit <- do.call("glm", list(formula=formula, family=poisson(),
data=data, weights = call("-", 1, as.name(zname)), ...))
this works ok, but i find that the call component of the fit object
returned by glm() has taken things a bit too literally -- it has
literals for all of the args in the call, rather than variable and
function names as the object returned by the first form above would. in
a simpler example,
> fun <- function(x, f) print(match.call())
> xx <- 1:10
> fun(x, sum)
fun(x = x, f = sum)
> do.call("fun", list(x = xx, f = sum))
fun(x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), f = function (...,
na.rm = FALSE)
.Internal(sum(..., na.rm = na.rm)))
this sure is ugly -- can anyone offer a way to get around it? that is,
i'd like to have fit$call look like it would for a direct call to glm(),
with the user-supplied variable name nicely substituted into the
weights= arg. as i understand it, i can't get around using do.call().
thanks for any help.
- peter
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list