1

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?

James
  • 673
  • 6
  • 19
  • 1
    Possible duplicate of [How to find out which package version is loaded in R?](https://stackoverflow.com/questions/11103189/how-to-find-out-which-package-version-is-loaded-in-r) – NelsonGon Apr 14 '19 at 07:16
  • 1
    No, I'm not looking for package versions, I'm looking for the list of loaded packages that contain a particular function, and in particular, which one is masking the others. The answer from @H_1 (use "conflicts(detail=T") is the general version of what I am looking for, though it would be nice to be able to add a specific function to that command to get more targeted results. – James Apr 16 '19 at 22:08

1 Answers1

3

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
Ritchie Sacramento
  • 29,890
  • 4
  • 48
  • 56