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屋!