假设我正在开发一个名为的包,foo它希望使用包中的description函数memisc.我不想导入整个memisc命名空间,因为:
memisc覆盖基本aggregate.formula函数,它打破了几件事.例如,example(aggregate) 会悲惨地失败.该软件包包括以下文件:
描述
Package: foo
Version: 0.0
Title: Foo
Imports:
memisc
Collate:
'foo.R'
Run Code Online (Sandbox Code Playgroud)
NAMESPACE
export(bar)
importFrom(memisc,description)
Run Code Online (Sandbox Code Playgroud)
R/foo.R
##' bar function
##'
##' @param x something
##' @return nothing
##' @importFrom memisc description
##' @export
`bar` <- function(x) {
description(x)
}
Run Code Online (Sandbox Code Playgroud)
我认为使用importFrom 不会加载整个memisc命名空间,但只是namespace::description,但事实并非如此.从香草R开始:
R> getS3method("aggregate","formula")
## ... function code ...
## <environment: namespace:stats>
R> library(foo)
R> getS3method("aggregate","formula")
## ... function code …Run Code Online (Sandbox Code Playgroud)