R:2个函数在2个不同的包中具有相同的名称 [英] R: 2 functions with the same name in 2 different packages
问题描述
我需要加载到R包:tseries和chron
I need to load to R packages : tseries and chron
两者都有一个名为is.weekend的函数
Both have a function named is.weekend
我总是在我的环境中使用我加载的第二个包中的函数。
I always have in my environment the function from the second package I loaded.
我怎样才能访问函数,比如说,chron?
How can I access always the function from, let say, chron ?
推荐答案
您可能已经注意到加载包的顺序有所不同,即最后加载的包将掩盖包中的函数加载前。
You have probably already noticed that the order of loading the packages makes a difference, i.e. the package that gets loaded last will mask the functions in packages loaded earlier.
要指定要使用的包,语法是:
To specify the package that you want to use, the syntax is:
chron::is.weekend()
tseries::is.weekend()
换句话说,使用 packagename :: functionname()
另外,如果您知道你总是希望在chron中使用这个函数,你可以定义你自己的函数,如下所示:
In addition, if you know that you will always want to use the function in chron, you can define your own function as follows:
is.weekend <- chron::is.weekend #EDIT
这篇关于R:2个函数在2个不同的包中具有相同的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!