问题
select()
belongs to both the dplyr
and MASS
namespaces.
Ambiguity about what is called with select()
can be solved by either
- Loading
dplyr
after loadingMASS
- Using
dplyr::select
rather than simplyselect
Is there any other solution, preferably one that involves nominating a library to take priority over others?
Extra note: I know in the world of CSS, there's an !important
attribute that can be added to a style so that it overrides others. I wonder if something similar exists in R which can be called when library(dplyr)
.
回答1:
Not sure whether it completely solves your problem, but one option could be to use conflict_prefer()
from conflicted
library. From the documentation:
conflict_prefer() allows you to declare "winners" of conflicts. You can either declare a specific pairing (i.e. dplyr::filter() beats base::filter()), or an overall winner (i.e. dplyr::filter() beats all comers).
Let's say you want to use between()
from data.table
:
conflict_prefer("between", winner = "data.table", quiet = FALSE)
[conflicted] Removing existing preference
[conflicted] Will prefer data.table::between over any other package
来源:https://stackoverflow.com/questions/58476313/force-one-namespace-to-override-take-priority-over-another-without-changing-lo