packages - "import as" in R -
is there way import bundle name in r, way might import as
in python, e.g. import numpy np
? i've been starting utilize package::function
lately avoid conflicts between, say, hmisc::summarize
, plyr::summarize
.
i'd able instead write h::summarize
, p::summarize
, respectively. possible in r?
here's solution should used interactive mode. modify ::
can take character bundle names, write function register aliases.
`::` <- function(pkg, name) { sym <- as.character(substitute(pkg)) pkg <- trycatch(get(sym, envir=.globalenv), error=function(e) sym) name <- as.character(substitute(name)) getexportedvalue(pkg, name) } pkg.alias <- function(alias, package) { assign(alias, package, .globalenv) lockbinding(alias, .globalenv) } pkg.alias('r', 'reshape2') r::dcast
but instead of using aliases, redefine ::
find bundle matches abbreviation:
`::` <- function(pkg, name) { pkg <- as.character(substitute(pkg)) pkg <- installed.packages()[grepl(paste0('^', pkg), installed.packages())] name <- as.character(substitute(name)) getexportedvalue(pkg, name) } ggp::ggplot
r packages
No comments:
Post a Comment