replace_nodes | R Documentation |
This function traverses the given RStatic object, calls the given replace function on each node, and replaces each node with the result of the call.
replace_nodes(node, replace, ..., in_place = FALSE)
node |
(ASTNode) The RStatic object to traverse. |
replace |
(function) The function to call on each node. |
... |
Additional arguments to the replace function. |
in_place |
(logical) Copy |
Replacement happens from the bottom up, so node
is replaced last.
find_nodes()
rename_symbols = function(node, name, newname)
{ # Rename symbols to something else.
if (is(node, "Symbol") && node$value == name)
node$value = newname
node
}
ast = quote_ast(ans <- sum(x, y / x, z))
replace_nodes(ast, rename_symbols, "x", "newx")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.