R: 2 functions with the same name in 2 different packages

女生的网名这么多〃 提交于 2019-11-26 15:50:52

问题


I need to load to R packages : tseries and chron

Both have a function named is.weekend

I always have in my environment the function from the second package I loaded.

How can I access always the function from, let say, chron ?


回答1:


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()

In other words, use packagename::functionname()

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



回答2:


library(chron)
is.weekend.chron <- is.weekend
library(tseries)

then you can call is.weekend for the tseries version or is.weekend.chron for the chron version



来源:https://stackoverflow.com/questions/5564564/r-2-functions-with-the-same-name-in-2-different-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!