S: Evaluates a call as if its function was defined in a...

Description Usage Arguments Details Value Examples

View source: R/S_function.R

Description

When a name is encountered in the body of a function, the search path for that name is given by the defining (or enclosing) environment of the function. This is good behaviour, since it allows simple reasoning about how a function should behave: If two calls to a function defined in a constant environment e yield different results, this must be because they are given different arguments.

Usage

1
S(call, env = parent.frame(), quote = TRUE)

Arguments

call

The function call to evaluate.

env

The environment where the function is defined. Defaults to parent.frame, which makes the defining environment equal to the current environment.

quote

Logical; If TRUE, substitutes the argument.

Details

Sometimes, a function is defined to make messy code more readable, but is only intended to be used once. In these cases, you might want to call the function as if it was defined in the body of the work you're currently working with. And that is what this function does for you.

Value

The value of the function call when evaluated in the specified environment.

Examples

1
2
3
4
5
6
7
8
9
   x = 3
   f = function() x^2
   g = function() {
     x = 10
     S(f())
   }
   g() # Evalutes to 100
   f() # Evalutes to 9
   S(f()) # Evaluates 9

JonasMoss/SPQR documentation built on Oct. 30, 2019, 7:58 p.m.