Skip to content

Instantly share code, notes, and snippets.

@jokergoo
Created October 7, 2014 18:34
Show Gist options
  • Save jokergoo/31b95dcbbc8fa3fb8fa6 to your computer and use it in GitHub Desktop.
Save jokergoo/31b95dcbbc8fa3fb8fa6 to your computer and use it in GitHub Desktop.
set_module = function(module) {
assign("__module__", module, envir = parent.frame())
}
load_module = function(file) {
e = new.env()
source(file, local = e, verbose = FALSE)
module = get("__module__", envir = e)
rm(e)
pos = which(search() == paste0("module:", module))
if(length(pos)) {
# detach it
detach(pos)
}
ns = attach(NULL, name = paste0("module:", module))
source(file, local = ns, verbose = FALSE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment