On Thu, Jun 27, 2013 at 8:49 PM, Ben Bolker <bbol...@gmail.com> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
>   The lmer() function in the lme4 package has some code of the form
>
> mc <- match.call()
> mc[[1]] <- as.name("lFormula")
> lmod <- eval(mc, parent.frame(1L))
>
>   this is a fairly common idiom in R, found e.g. in lm(), used when
> one wants to pass all of the arguments of a function to a different
> function (in the case of lm() it's model.frame()).
>

I think the use of stack inspection ( usually parent.frame(), but with
match.call() often playing an accessory role) should be more widely
considered Evil, but I could get very off topic on that.

Passing along all the current function's arguments to another function is
implemented fairly well in S3 method dispatch. For example:

###

aMethod <- function(...) UseMethod("aMethod")

aMethod.default <- function(object, continue) {
  if (continue) {
    .Class <- "alternate"
    NextMethod()
  }
  c("default", object)
}

aMethod.alternate <- function(object, continue) {
  c("alternate", object)
}

x <- "this is the wrong x"

local({
  x <- "this is the right x"
  aMethod(x, TRUE)
})

###

Peter

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to