ReplaceInExpression {gramEvol} | R Documentation |
Replace as sub-expression isnide an expression
Description
Replace every subexpression equal to or starting with what
in expr
.
Replacement is performed by passing the whole subexpression to replacer.func
,
which should be a function(x, ...)
, where x
is the expression and return the desirable expression.
Usage
ReplaceInExpression(expr, what, replacer.func, ...)
Arguments
expr |
An |
what |
A backquoted expression to find in |
replacer.func |
A |
... |
Other parameters passed to |
Details
This function was designed to be used as a runtime processing tool for grammar generated expression. This allows the user to modify the resulting expression on the fly based on runtime variables, without including them in the grammar. See examples section.
Value
An expression
References
See http://adv-r.had.co.nz/Expressions.html by Hadley Wickham.
Examples
expr = expression(function(x) {
cbind(f1(x),
f2(x),
g3(y))
})
expr
ReplaceInExpression(expr, bquote(f2), function(x) {NULL})
ReplaceInExpression(expr, bquote(f2), function(x) {bquote(f2(y))})
ReplaceInExpression(expr, bquote(g3), function(x) {bquote(f3(x))})
ReplaceInExpression(expr, bquote(g3), function(x, b) {if (b > 1) x else NULL}, b = 0)
ReplaceInExpression(expr, bquote(g3), function(x, b) {if (b > 1) x else NULL}, b = 2)
[Package gramEvol version 2.1-4 Index]