body_replace {factory} | R Documentation |
Replace quoted targets in the body of a function with quoted replacements.
body_replace(fn_body, target, replacement)
fn_body |
The body of a function (as found via body(fun)). |
target |
A quoted expression to replace. |
replacement |
A quoted expression with which the target should be replaced. |
A function body with the target replaced anywhere it occurs.
fun <- function(x) {
x^exp
}
body_replace(body(fun), quote(exp), quote(!!exp))