In loading a few packages to work with some data, I received an error when I tried to use the function select() from the dplyr package. I was trying to use a new package (to me), MASS, so I was easily able to diagnose and get things working properly. This experience made me curious, though, about the optimal way to work in a world of many packages, with functions that conflict with one another.
Consider the following code and error message:
library(dplyr)
library(MASS)
df<-data.frame(Lobsters=c(1,3,4,5,7,1),Llamas=c(7,1,2,5,8,3))
df2<-df%>%
select(Lobsters)
Error in select(.,Lobsters) : unused argument (Lobsters)
While this error makes it clear that select() is giving me the problem, it doesn't necessarily make it clear to me that the problem is that I'm not calling on the select() function I'm used to.
I know I can call the dplyr function and get my desired result using:
df2_alt<-df%>%
dplyr::select(Lobsters)
I wonder, though:
Is there a best practice in diagnosing problems with same-named functions, besides the "The following object is masked from" messages when a package is loaded?
Is my method of
dplyr::select(the best way to work around these conflicts?
Ultimately, my current strategy is to load the package that has the select() function I'll be using more after the package that has the less-frequently-used version.