rmatch_calls: Recursively expand match calls in an expression from the...

Description Usage Arguments Value Examples

View source: R/rmatch_calls.R

Description

Given an expression, expr, traverse the syntax tree from the bottom up, expanding the call to include default values of named formals as appropriate, and applying match.call to the result. Functionality is limited to expressions containing ordinary functions or S3 methods. If parameter eval_for_class has its default value of FALSE, an error will be raised for any S3 method whose first argument (as an expression) is not atomic. If eval_for_class is TRUE, the first argument will be evaluated to determine its class. Evaluation will take place in the environment given by parameter eval_env. CAUTION: eval_for_class=TRUE is likely to result in multiple evaluations of the same code. Expressions containing S4 or reference class methods will also raise errors.

Usage

1
rmatch_calls(expr, eval_for_class = FALSE, eval_env = NULL)

Arguments

expr

an R expression (a.k.a. abstract syntax tree)

eval_for_class

TRUE or FALSE. If TRUE, evaluate the first argument of an S3 method to determine its class. Default=FALSE.

eval_env

environment in which to evaluate for class. Ignored if eval_for_class=FALSE

Value

an equivalent R expression with function or method calls in canonical form.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: rmatch_calls(quote(help("print")))
## Not run: # S3 method with atomic first argument
rmatch_calls(quote(seq(0, 1, by=.5)))
## End(Not run)
## Not run: # S3 method with non-atomic first argument, eval_for_class = FALSE (default)
rmatch_calls(quote(seq(as.Date("2014-02-01"), as.Date("2014-03-01"))))
## End(Not run)
## Not run: # S3 method with non-atomic first argument, eval_for_class = TRUE
rmatch_calls(quote(seq(as.Date("2014-02-01"), as.Date("2014-03-01"))), eval_for_class=TRUE)
## End(Not run)

HJ08003/socraticswirl-RStudioServer documentation built on May 20, 2019, 11:10 a.m.