R:2个不同包中的2个同名函数 [英] R: 2 functions with the same name in 2 different packages

查看:40
本文介绍了R:2个不同包中的2个同名函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要加载到 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屋!

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