Created
May 9, 2016 13:32
-
-
Save wjhopper/13c68c00a1de9548a868e405973894dc 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