“导入为"在R中 [英] "import as" in R

查看:59
本文介绍了“导入为"在R中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以导入R中具有其他名称的包,就像您在Python中使用import as时那样,例如import numpy as np?我最近开始使用package::function来避免Hmisc::summarizeplyr::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::summarizep::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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆