Description Usage Arguments Value Examples
Function to replace variables in function body expr is 'body(f)', keyvals is a lookup table for replacements
1 | rep_vars(expr, keyvals)
|
expr |
body of function for example, ie 'body(func)' |
keyvals |
named lookup |
new expression with substituted variables
1 2 3 4 5 6 7 8 9 10 11 | # replace the formals of a function and its body variables
# http://stackoverflow.com/questions/33850219/change-argument-names-inside-a-function-r
## Not run:
f <- function(x, y) -x^2 + x + -y^2 + y
newvals <- c('x'='x0', 'y'='y0') # named lookup vector
newbod <- rep_vars(body(f), newvals) # create new body
# Rename the formals, and update the body
formals(f) <- pairlist(x0=bquote(), y0=bquote())
body(f) <- newbod
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.