在R 2.14.0程序包检查中,DESCRIPTION Imports的顺序:和NAMESPACE import() [英] Order of DESCRIPTION Imports: and NAMESPACE import() in R 2.14.0 package checking

查看:153
本文介绍了在R 2.14.0程序包检查中,DESCRIPTION Imports的顺序:和NAMESPACE import()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我检查程序包时,我试图找出函数名称之间似乎有冲突的地方.我最终可能会直接问这个问题,但是首先,我想知道三件事,R-exts中似乎都没有提到:

I'm trying to chase down what seems to be a conflict between function names as I check a package. I may eventually ask directly about the problem, but first, I am wondering about three things, none of which seem to be mentioned in R-exts:

  1. DESCRIPTION:Imports和NAMESPACE imports()中列出的软件包应该相同,对吧?
  2. 在任一列表中,导入顺序都重要吗?如果是这样,是否有关于如何订购它们的一般建议?
  3. 我使用R --vanilla CMD检查pkg_name以避免干扰我的.Rprofile.当我的.Rprofile处于活动状态并包含library(pkg_name)语句时,这些命令的顺序重要吗?

推荐答案

您问了三个问题.

DESCRIPTION Imports:中列出的每个程序包都必须具有匹配的条目NAMESPACE import(...). DESCRIPTION中的条目可能包含版本信息,但是在NAMESPACE中,您只为软件包命名.

Each package listed in DESCRIPTION Imports: must have a matching entry NAMESPACE import(...). The entry in DESCRIPTION may contain version information, but in NAMESPACE you only name the package.

注意事项:拼写Imports时用大写字母I并在描述中尾随s

Note for the unwary: Spell Imports with capital I and trailing s in DESCRIPTION

例如:

说明

Imports:
    stringr (>= 0.5)

NAMESPACE

import(stringr)

2.订单很重要

您以后loadimport的软件包会掩盖之前加载或导入的软件包.仅当您导入具有导出具有相同名称的功能的程序包时,这才重要.

2. Order matters

Packages that you load or import later masks packages that were loaded or imported earlier. This only matters if you import packages that have export a function with identical name.

例如,latticeggplot2都导出layer函数.因此,如果先导入lattice,然后再导入ggplot2,则意味着ggplot2::layer将掩盖lattice::layer.

For example, both lattice and ggplot2 export a layer function. Thus if you first import lattice and then ggplot2, it means that ggplot2::layer will mask lattice::layer.

换句话说,使用layer将引用ggplot2::layer.如果要引用lattice版本,则需要在函数中显式引用lattice::layer.

In other words, using layer will refer to ggplot2::layer. If you want to refer to the lattice version you need to explicitly refer to lattice::layer in your function.

出于相同的原因,加载程序包的顺序(在脚本或.Rprofile中)也很重要.您加载的任何新软件包都会掩盖以前加载的软件包中具有相同名称的功能.

For the same reason, the order of loading packages (either in a script or in .Rprofile) matters. Any new package that you load will mask functions with the same name in previously loaded packages.

发生这种情况时,R会做明智的事情,并在控制台消息中告诉您.

When this happens, R does the sensible thing and tells you about it in a console message.

以下是在加载reshape软件包时发生的屏蔽的示例,该软件包取决于plyr但也屏蔽了plyr中的某些功能:

Here is an example of masking that occurs when loading the reshape package, which depends on plyr but also masks some functions in plyr:

library(reshape)
Loading required package: plyr

Attaching package: 'plyr'

The following object(s) are masked from 'package:braidppt':

    .


Attaching package: 'reshape'

The following object(s) are masked from 'package:plyr':

    rename, round_any

这篇关于在R 2.14.0程序包检查中,DESCRIPTION Imports的顺序:和NAMESPACE import()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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