Detect conflicts between packages in R [duplicate]

喜欢而已 提交于 2019-12-01 03:35:43

As @Paul says, when attaching (e.g. via library function) a package you may get:

> library("gdata", lib.loc="C:/Program Files/R/R-2.15.3/library")
gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.

gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED.

Attaching package: ‘gdata’

The following object(s) are masked from ‘package:stats’:

    nobs

The following object(s) are masked from ‘package:utils’:

    object.size

When you get "The following object(s) are masked" mean that calls to those function will be thought by R as calls to the functions in the new package, in my example gdata.

You can avoid this via:

> nobs
function (object, ...) 
UseMethod("nobs")
<environment: namespace:gdata>
> stats::nobs
function (object, ...) 
UseMethod("nobs")
<bytecode: 0x0000000008a92790>
<environment: namespace:stats

hope that helps

If R loads a new package, it will produce a warning if that new package contains any functions that are already present in the working environment. So if you pay attention during package loading, you can see if there are any conflicts. When there are conflicts, you can force R to use the function from a particular package like this:

package_name::function_name

I think you're looking for getAnywhere which will tell you all the places its argument exists. E.g. (in my current load set):

Rgames> getAnywhere(logit)
2 differing objects matching ‘logit’ were found
in the following places
  package:boot
  package:pracma
  namespace:boot
  namespace:pracma
Use [] to view one of them
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!