-
-
Save ddbs/5f64b5c56adb1d532813ffa6db8882c8 to your computer and use it in GitHub Desktop.
Metaprogramming in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a function programmatically by creating its constituents: | |
# an argument list, a function body of expressions, and an enclosing environment | |
args <- alist(x=,y=) | |
exps <- expression(z <- x^2 + y^2, z <- sqrt(z), return(z)) | |
body <- as.call(c(as.name("{"), exps)) | |
f <- as.function(x = c(args,body), envir = parent.frame()) | |
f(x=1,y=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment