How can I prevent a library from masking functions

前端 未结 5 1048
一个人的身影
一个人的身影 2021-02-04 06:21

A typical situation is the following:

library(dplyr)
library(xgboost)

When I import the library xgboost, the function slice<

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 06:50

    You can also now use the conflict_prefer() function from the conflicted package to specify which package's function should "win" and which should be masked when there are conflicting function names (details here). In your example, you would run

    conflict_prefer("slice", "dplyr", "xgboost") 
    

    right after loading your libraries. Then when you run slice, it will default to using dplyr::slice rather than xgboost::slice. Or you can simply run

    conflict_prefer("slice", "dplyr")
    

    if you want to give dplyr::slice precedence over all other packages' slice functions.

提交回复
热议问题