最小示例:我有一个R包,其唯一的.R文件包含代码
data.table::data.table(iris)[Species == "setosa"]
预期产出:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1: 5.1 3.5 1.4 0.2 setosa
2: 4.9 3.0 1.4 0.2 setosa
...
交互式运行良好(使用knitr和r --vanilla
进行编译时)。
但是,当我在软件包上运行R CMD INSTALL
时,它会失败并显示:
Error in `[.data.frame`(x, i, j) : object 'Species' not found
为什么这只会在R CMD INSTALL中发生,我该如何避免呢?
的详细说明: 的
套餐进口
包描述文件包含
行Imports: data.table
失败的R CMD INSTALL的成绩单
Rcmd.exe INSTALL --no-multiarch --with-keep.source MYPKG
* installing to library 'C:/Users/.../Documents/R/win-library/3.2'
* installing *source* package 'MYPKG' ...
** R
** inst
** preparing package for lazy loading
Error in `[.data.frame`(x, i) : object 'Species' not found
Error : unable to load R code in package 'MYPKG'
ERROR: lazy loading failed for package 'MYPKG'
* removing 'C:/Users/.../Documents/R/win-library/3.2/MYPKG'
* restoring previous 'C:/Users/.../Documents/R/win-library/3.2/MYPKG'
Exited with status 1.
版本信息
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)
locale:
[1] LC_COLLATE=Norwegian (Bokmål)_Norway.1252
[2] LC_CTYPE=Norwegian (Bokmål)_Norway.1252
[3] LC_MONETARY=Norwegian (Bokmål)_Norway.1252
[4] LC_NUMERIC=C
[5] LC_TIME=Norwegian (Bokmål)_Norway.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] data.table_1.9.7 chron_2.3-47
答案 0 :(得分:2)
您应该始终需要维护NAMESPACE
个文件,而不仅仅是DESCRIPTION
import(data.table)
到NAMESPACE填写将解决您的问题。