[英]Order of DESCRIPTION Imports: and NAMESPACE import() in R 2.14.0 package checking
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: 我最终可能会直接询问这个问题,但首先,我想知道三件事情,R-exts中似乎都没有提及:
You asked three questions. 你问了三个问题。
DESCRIPTION
as well as NAMESPACE
1.列出DESCRIPTION
和NAMESPACE
Each package listed in DESCRIPTION
Imports:
must have a matching entry NAMESPACE
import(...)
. DESCRIPTION
Imports:
列出的每个包都必须具有匹配的条目NAMESPACE
import(...)
。 The entry in DESCRIPTION
may contain version information, but in NAMESPACE
you only name the package. DESCRIPTION
的条目可能包含版本信息,但在NAMESPACE
您只能命名包。
Note for the unwary: Spell Imports
with capital I
and trailing s
in DESCRIPTION 注意粗心:拼写Imports
资本I
和尾s
的说明
For example: 例如:
DESCRIPTION 描述
Imports:
stringr (>= 0.5)
NAMESPACE NAMESPACE
import(stringr)
Packages that you load
or import
later masks packages that were loaded or imported earlier. 您稍后load
或import
软件包会屏蔽先前加载或导入的软件包。 This only matters if you import packages that have export a function with identical name. 这仅在导入导出具有相同名称的函数的包时才有意义。
For example, both lattice
and ggplot2
export a layer
function. 例如, lattice
和ggplot2
导出layer
函数。 Thus if you first import lattice
and then ggplot2
, it means that ggplot2::layer
will mask lattice::layer
. 因此,如果您首先导入lattice
然后导入ggplot2
,则意味着ggplot2::layer
将屏蔽lattice::layer
。
In other words, using layer
will refer to ggplot2::layer
. 换句话说,使用layer
将引用ggplot2::layer
。 If you want to refer to the lattice
version you need to explicitly refer to lattice::layer
in your function. 如果要引用lattice
版本,则需要在函数中显式引用lattice::layer
。
For the same reason, the order of loading packages (either in a script or in .Rprofile) matters. 出于同样的原因,加载包的顺序(在脚本或.Rprofile中)很重要。 Any new package that you load will mask functions with the same name in previously loaded packages. 您加载的任何新包将在先前加载的包中屏蔽具有相同名称的函数。
When this happens, R does the sensible thing and tells you about it in a console message. 当发生这种情况时,R会做出明智的事情并在控制台消息中告诉您。
Here is an example of masking that occurs when loading the reshape
package, which depends on plyr
but also masks some functions in plyr
: 下面是加载reshape
包时发生的屏蔽示例,它取决于plyr
但也会屏蔽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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.