ReplaceInExpression | R Documentation |
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.
ReplaceInExpression(expr, what, replacer.func, ...)
expr |
An |
what |
A backquoted expression to find in |
replacer.func |
A |
... |
Other parameters passed to |
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.
An expression
See http://adv-r.had.co.nz/Expressions.html by Hadley Wickham.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.