Force one namespace to override / take priority over another without changing load order?

谁说我不能喝 提交于 2019-12-24 03:00:13

问题


select() belongs to both the dplyr and MASS namespaces.

Ambiguity about what is called with select() can be solved by either

  1. Loading dplyr after loading MASS
  2. Using dplyr::select rather than simply select

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!