Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 570
RockScience Avatar asked Apr 06 '11 10:04

RockScience


1 Answers

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 
like image 78
Andrie Avatar answered Oct 07 '22 12:10

Andrie