Reputation: 673
When I have multiple packages containing a function, how do I confirm which package's version of a function is invoked if I call it (without explicitly naming the package)? I've looked at How to know to which package a particular function belongs to in R prior to package loading?
and narrowed down (my particular problem was "arima") the suspects using
help.search('arima', fields=c('name'), ignore.case=FALSE, agrep=FALSE)
In my case this returns "stats" and "TSA" as the only possible culprits, but this still doesn't tell me which is active. The system obviously knows, or we would have to be explicit whenever we call functions. But how do we obtain this information?
Upvotes: 1
Views: 878
Reputation: 34511
You can find out which functions are in conflict (being masked) by using conflicts(detail = TRUE)
. This returns a named list of packages / functions in conflict in the order of the search()
path which is the order in which they will be called.
As an example, we can load dplyr
which loads some functions that conflict with base.
library(dplyr)
# Create data.frame of conflicts and clean up.
conf <- conflicts(detail = TRUE)
conf.df <- data.frame(do.call(rbind, Map(cbind, conf, names(conf))))
names(conf.df) <- c("fn", "package")
conf.df$package <- sub("package:", "", conf.df$package)
# Aggregate packages by function - first package is the default when called.
aggregate(package ~ fn, conf.df, toString)
fn package
1 body<- methods, base
2 filter dplyr, stats
3 intersect dplyr, base
4 kronecker methods, base
5 lag dplyr, stats
6 setdiff dplyr, base
7 setequal dplyr, base
8 union dplyr, base
Upvotes: 4