我可以知道,使用导入来加载命名空间中的函数是最好的在描述文件中使用。
添加到描述文件后,我也将其添加到命名空间文件。
我将importFrom添加到具有所需函数的命名空间文件。
现在当我运行R CMD检查我的包,
我得到一个错误
Namespace dependencies not required :
‘ggplot2’
更多信息:即使我将包添加到描述文件中的依赖,它们也不会被加载。
请帮助这个。
请在下面找到我的描述文件
Package: bigpackage
Type: Package
Title: Some title
Version: 1.0
Date: 2012-10-25
Author: Mayank Bansal
Maintainer: somename
Imports : R(>= 2.15.1),SweaveListingUtils( >=0.5.5),xtable(>=1.7-0),
brew(>=1.0-6),knitr(>=0.8),RHive(>= 0.0-6),ggplot2(>=0.9.2)
,brew,knitrSystemRequirements : LaTeX(texi2dvi) must be present in the system to
create PDF reportsDescription: Some Description
License: file LICENSE
LazyLoad: yes
ByteCompile: true
OS_type : unix
这里是Writing R Extensions的相关部分
The ‘Imports’ field lists packages whose namespaces are imported from (as specified in the NAMESPACE file) but which do not need to be attached. Namespaces accessed by the ‘::’ and ‘:::’ operators must be listed here,or in ‘Suggests’ or ‘Enhances’ (see below). Ideally this field will include all the standard packages that are used,and it is important to include S4-using packages (as their class definitions can change and the DESCRIPTION file is used to decide which packages to re-install when this happens). Packages declared in the ‘Depends’ field should not also be in the ‘Imports’ field.
我做了一个单一的函数f的包。我做了一个NAMESPACE文件,具有相同的importFrom行,你说你在你的。
NAMESPACE文件
export("f") importFrom("ggplot2","ggplot","geom_histogram")
在这一点上,如果我运行R CMD检查,如预期,我得到一个错误:
Namespace dependency not required: ‘ggplot2’
但是,如果我添加Imports:ggplot2到DESCRIPTION,使我的DESCRIPTION文件如下,它通过R CMD检查没有问题。
DESCRIPTION文件
Package: anRpackage Type: Package Title: What the package does (short line) Version: 1.0 Date: 2012-11-07 Author: Me Maintainer: Who to complain to <yourfault@somewhere.net> Description: More about what it does (maybe more than one line) License: GPL Imports: ggplot2