scope: Scoped Evaluation

Description Usage Arguments Details Value See Also Examples

View source: R/scope.R

Description

Evaluate an expression in the context of a data environment.

Usage

1
2
3
scope(x, expr, envir = NULL)

scopeQuoted(x, expr, envir = NULL)

Arguments

x

a list or data object.

expr

an object to be evaluated.

envir

an enclosing environment, or NULL for the calling frame.

Details

The scopeQuoted evaluates its expr argument in a context that by default looks for names first in x and then in envir. If the expression contains a call to I() then the argument of that call gets evaluatedc in the environment envir, not in x.

The scope function quotes its expr argument and then calls scopeQuoted.

The scope evaluation mechanism gets used in all functions in the ‘frame’ package that require non-standard evaluation. It is similar to the evaluation mechanism used by the model.frame function, but is otherwise not used in base R.

Value

The result of the evaluated expression expr.

See Also

select, transform.dataset.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
x <- list(a = 1:10, b = 10 * (1:10))
a <- 100000000
c <- 1000

# look up first in 'x', then in the calling environment
scope(x, a * b + c)

# look up 'a' in the calling environment, not in 'x'
scope(x, I(a) * b + c)

# evaluate a quoted expression
scopeQuoted(x, quote(a + c)) # equivalent to scope(x, a + c)

patperry/r-frame documentation built on May 6, 2019, 8:34 p.m.