[R] evaluating variables in the context of a data frame

From: Zack Weinberg <zackw_at_panix.com>
Date: Thu, 07 Jun 2007 22:01:11 -0700


Given

> D = data.frame(o=gl(2,1,4))

this works as I expected:

> evalq(o, D)

[1] 1 2 1 2
Levels: 1 2

but neither of these does:

> f <- function(x, dat) evalq(x, dat)
> f(o, D)

Error in eval(expr, envir, enclos) : object "o" not found
> g <- function(x, dat) eval(x, dat)
> g(o, D)

Error in eval(x, dat) : object "o" not found

What am I doing wrong? This seems to be what the helpfiles say you do to evaluate arguments in the context of a passed-in data frame...

zw



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 08 Jun 2007 - 05:07:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Jun 2007 - 06:32:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.