Tuesday, 9 February 2016

"The following objects are masked from" error in R; Function name conflicts while using multiple packages in RStudio

Hi,

If you get the error message saying "The following objects are masked from _____ package" while loading an R package in RStudio, it is because the package you've loaded and the package shown in the error message are using objects with the same name. So when you call the object, it will be called from the package you've loaded most recently before calling the object.

The best way to use objects from both packages in a script is calling the objects in the fashion of packageName::objectName .

Eg: R script

install.packages("distr")
require(distr)
sdFromDistr = distr::sd(c(1,2,3))
sdFromStats = stats::sd(c(1,2,3))

In this case since sd object from both packages are used for same functionality, you'll be getting same answer. But this tip is highly useful when the objects from different packages are used for different purposes.

Hope this helps you in someway.

All the best in your life.

No comments:

Post a Comment