我正在尝试构建一个R包,以便阅读CRAN上的手册.我可以弄清楚使用导入来加载命名空间中的函数将是在Description文件中使用的最佳选择.添加到描述文件后,我还将其添加到命名空间文件中.我将importFrom添加到具有所需功能的命名空间文件中.
现在,当我在我的包装上运行R CMD检查时,我得到了一个错误
不需要命名空间依赖项:'ggplot2'
更多信息:即使我将包添加到描述文件中的Depends,它们也不会被加载.
请帮忙.
请在下面找到我的描述文件
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, knitr
SystemRequirements : LaTeX(texi2dvi) must be present in the system to
create PDF reports
Description: Some Description
License: file LICENSE
LazyLoad: yes
ByteCompile: true
OS_type : unix
Run Code Online (Sandbox Code Playgroud) R的命名空间机制允许一个export用户可见的功能.此外,它允许import从其他包中起作用.虽然出口的好处是显而易见的,但我在理解进口的好处方面存在更多问题.
似乎有一个好处是,可以使用其他软件包中的函数而无需附加软件包,从而节省内存.这在写作R扩展手册的1.6.4节中有所例证.
但是,导入功能必须具有其他好处.特别是,第1.6.6节(处理S4类)显示namespace了stats4包:
export(mle)
importFrom("graphics", plot)
importFrom("stats", optim, qchisq)
## For these, we define methods or (AIC, BIC, nobs) an implicit generic:
importFrom("stats", AIC, BIC, coef, confint, logLik, nobs, profile,
update, vcov)
exportClasses(mle, profile.mle, summary.mle)
## All methods for imported generics:
exportMethods(coef, confint, logLik, plot, profile, summary, show, update, vcov)
## implicit generics which do not have any methods here
export(AIC, BIC, nobs)
Run Code Online (Sandbox Code Playgroud)
这里导入的函数既不是S4类也不是泛型(使用import也是有意义的,如该部分中的示例所述),但是函数类似于R启动时自动加载plot的 …