0 votes
1 view
in R Programming by (5k points)

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 Answer

0 votes
by (24.7k points)
edited by

To specify the package that you want to use for a function with the same name, the syntax is:

chron::is.weekend() 

tseries::is.weekend()

You would have 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.

In other words, use packagename::functionname() to avoid masking.

In addition, if you know that you will always want to use the function in chron package, you can define your own function as follows:

is.weekend <- chron::is.weekend

If you want to explore more in R programming then watch this R programming tutorial for beginner:

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...