[R] Small mystery : passing a "subset=" argument to lme|lm through "..."

Emmanuel Charpentier charpent at bacbuc.dyndns.org
Thu Jun 4 17:47:36 CEST 2009


Dear list,

I have problems involving passing a "subset=" argument through "...".
I'm trying to augment the set of defined analyses for mice (homonymous
package) with a call to lme. This package create multiple imputations of
missing data in a "mids" object, each completed data set may be obtained
through the complete(data, set) function.

> sessionInfo()
R version 2.9.0 (2009-04-17) 
x86_64-pc-linux-gnu 

locale:
LC_CTYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;LC_MONETARY=C;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods
base     

other attached packages:
[1] odfWeave_0.7.10 XML_2.3-0       lattice_0.17-25

loaded via a namespace (and not attached):
[1] grid_2.9.0   MASS_7.2-47  nlme_3.1-92  rpart_3.1-44
> 

# First attempt : 
foo<-function(formula, data, ...) {
  library(nlme)
  call <- match.call()
  if (!is.mids(data))
    stop("The data must have class mids")
  analyses<-lapply(1:data$m, function(i) lme(formula,
                                             data=complete(data,i),
                                             ...))
  object <- list(call = call, call1 = data$call, nmis = data$nmis, 
                 analyses = analyses)
  oldClass(object) <- c("mira", oldClass(object))
  return(object)
}
> bar1<-foo(ttotal~nbpradio, data=Data1.Imp, random=~1|ctr)
> class(bar1$analyses[[1]])
[1] "lme" # Fine : the "random=" argument *HAS BEEN* passed to lme()
# through "..." ; therefore it's (usually) possible.
# Further tests (not shown) show that results are "reasonable" (i. e. 
# compliant with expectations...).
> bar2<-foo(log(ttotal)~log(nbpradio), data=Data1.Imp, random=~1|ctr,
subset=nbpradio>0)
Erreur dans eval(expr, envir, enclos) : 
  ..2 utilisé dans un mauvais contexte, aucun ... où chercher
> 

Further exploration show that a "subset=" argument *DOES NOT GET PASSED*
to lme(), which complaints furthermore not to find a "..." argument.
Since lme is a method private to the nlme package, I can't trace the
source of error.

[Later : Same observation with lm() instead of lme()...]

Now, ISTR that an analogous problem *has already been discussed* on this
list, but even a prolonged use of RSiteSearch() did not retrieve it.
http://finzi.psych.upenn.edu/R/Rhelp02/archive/10139.html hints that
"Modelling and graphics functions with formulas all have slightly 
different nonstandard evaluation rules, and it turns out that lme() 
doesn't evaluate extra arguments like subset in the parent environment",
but this does not tell me why a "..." argument is *not* found. Different
frame of evaluation ?

May some kind soul point me to the right direction ? (He may even
further my shame by telling me how he retrieved the relevant
information...).

Sincerely,

					Emmanuel Charpentier




More information about the R-help mailing list