Created
October 29, 2015 00:53
-
-
Save MrFlick/d8044fdb5eb594b799a3 to your computer and use it in GitHub Desktop.
export.R: copy variables from current environemnt to the calling environment
This file contains hidden or 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
export <- function(...) { | |
dots <- substitute(...()) | |
dp <- sapply(dots, deparse) | |
names <- if (is.null(names(dots))) rep("", length(dots)) else names(dots) | |
names[names==""] <- dp[names==""] | |
for(i in seq_along(dots)) { | |
assign(names[i], eval(dots[[i]], parent.frame()), envir=parent.frame(2)) | |
} | |
} |
This file contains hidden or 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
# copy variables from current environemnt to the calling environment | |
# optionally rename | |
givevals <- function() { | |
x <- 10 | |
y <- 30 | |
export(x, z=y) | |
} | |
hello<-function() { | |
givevals() | |
print(x) | |
print(z) | |
} | |
hello() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment