检测R中的软件包之间的冲突 [英] Detect conflicts between packages in R

查看:186
本文介绍了检测R中的软件包之间的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现错误可能是由于程序包之间的冲突引起的,也就是说,两个(或更多)程序包可能具有类似命名的函数.我知道代码search ()生成以R读取它们的方式排序的软件包列表.还有args代码,它提供了R读取的功能.
我想首先了解如何检测由于软件包之间的冲突而产生的错误,其次是如何找出哪个软件包.有冲突吗?最后,在检测到冲突之后,如何强制R使用其中一个软件包中的特定功能?

I've recently found out that errors can be caused due to conflicts between packages, that is, two (or more) packages might have functions named similarly. I know that the code search () produces the list of packages ordered in the way R reads them. There is also the args code which gives the function read by R.
What I would like to know firstly is how to detect if an error is being produced because of conflicts between packages and secondly how to find out which packages are conflicting? Finally, after the conflicts have been detected, how can we force R to use specifically the function from one of the packages?

推荐答案

正如@Paul所说,在附加(例如通过library函数)软件包时,您可能会得到:

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

当您获得以下对象被屏蔽"时,R会将对这些函数的调用视为对新包中函数的调用,在我的示例中为gdata.

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

希望有帮助

这篇关于检测R中的软件包之间的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆