“导入为"在R中 [英] "import as" in R
问题描述
是否有一种方法可以导入R中具有其他名称的包,就像您在Python中使用import as
时那样,例如import numpy as np
?我最近开始使用package::function
来避免Hmisc::summarize
和plyr::summarize
之间的冲突.
Is there a way to import a package with another name in R, the way you might with import as
in Python, e.g. import numpy as np
? I've been starting to use package::function
lately to avoid conflicts between, say, Hmisc::summarize
and plyr::summarize
.
我希望能够分别编写h::summarize
和p::summarize
.在R中可以吗?
I'd like to be able to instead write h::summarize
and p::summarize
, respectively. Is this possible in R?
推荐答案
Use the namespace package to generate another namespace aliased to the one you are interested in.
library(namespace)
registerNamespace('ggp', loadNamespace('ggplot2'))
data(iris)
ggp::ggplot(iris, ggp::aes(x = Petal.Length, y = Sepal.Length)) + ggp::geom_point()
请注意,这样做的缺点是使脚本的软件包版本控制/安装要求更加不透明.
Note this has the disadvantage of making the package versioning/installation requirements more opaque for scripts.
这篇关于“导入为"在R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!