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

Zack Weinberg zackw at panix.com
Fri Jun 8 07:01:11 CEST 2007


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



More information about the R-help mailing list