Skip to content

Instantly share code, notes, and snippets.

@cosi1
Created February 27, 2018 12:42
Show Gist options
  • Save cosi1/64a11cc5ba1a680d84b8796d11eec289 to your computer and use it in GitHub Desktop.
Save cosi1/64a11cc5ba1a680d84b8796d11eec289 to your computer and use it in GitHub Desktop.
# Imports a namespace under an alias
# (equivalent of Python's `import ... as ...`)
importAs = function(namespace, alias) {
namespace::registerNamespace(name = alias, env = asNamespace(namespace))
}
# Imports function(s) from a namespace (including unexported functions)
# to the global namespace
# (equivalent of Python's `import ... from ...`)
importFrom = function(namespace, functions) {
for (fun in functions) {
assign(
fun,
getFromNamespace(fun, ns = asNamespace(namespace)),
env = parent.frame()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment