This question and in particular this answer brought up the following question: How can I get a warning about the masking of methods in R?
If you run the following code
The conflicted
package (see here) now offers a potential solution to this problem. With conflicted
loaded, you get more explicit error messages about conflicting function names. You also can use conflict_prefer
(details here) to specify which package's function you want to use by default and which should be masked.
For example, here is a recent error I got when attempting to use the function parallel
from the nFactors
package:
# Error: [conflicted] `parallel` found in 2 packages.
# Either pick the one you want with `::`
# * nFactors::parallel
# * lattice::parallel
# Or declare a preference with `conflict_prefer()`
# * conflict_prefer("parallel", "nFactors")
# * conflict_prefer("parallel", "lattice")
I then added
conflict_prefer("parallel", "nFactors")
right after the code loading my libraries at the beginning of the script to make sure that parallel
would call nFactors::parallel
in my code.