Skip to content

Instantly share code, notes, and snippets.

@MrFlick
Created October 29, 2015 00:53
Show Gist options
  • Save MrFlick/d8044fdb5eb594b799a3 to your computer and use it in GitHub Desktop.
Save MrFlick/d8044fdb5eb594b799a3 to your computer and use it in GitHub Desktop.
export.R: copy variables from current environemnt to the calling environment
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))
}
}
# 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