将相同的env传递给eval中的envir和enclos?

时间:2014-10-25 15:06:53

标签: r eval

以下是magrittr包的摘录:

`%>%` <-
  function(lhs, rhs)
  {

      browser()

    # Capture unevaluated arguments
    lhs <- substitute(lhs)
    rhs <- substitute(rhs)

    # Should rhs be evaluated first due to parentheses?
    if (is.call(rhs) && identical(rhs[[1]], quote(`(`)))
      rhs <- eval(rhs, parent.frame(), parent.frame())
    ......
}

现在这里是关于eval的文档:

Usage:

     eval(expr, envir = parent.frame(),
                enclos = if(is.list(envir) || is.pairlist(envir))
                            parent.frame() else baseenv())

Arguments:

    expr: an object to be evaluated.  See ‘Details’.

   envir: the ‘environment’ in which ‘expr’ is to be evaluated.  May
          also be ‘NULL’, a list, a data frame, a pairlist or an
          integer as specified to ‘sys.call’.

  enclos: Relevant when ‘envir’ is a (pair)list or a data frame.
          Specifies the enclosure, i.e., where R looks for objects not
          found in ‘envir’.  This can be ‘NULL’ (interpreted as the
          base package environment, ‘baseenv()’) or an environment.

因此作者将parent.frame()传递给了envir和enclos,即,如果你在parent.frame()中找不到某个对象,请再次查看。我不知道这里有什么意义。

0 个答案:

没有答案