Jon Olav Vik
Jon Olav Vik

Reputation: 1461

data.table works in console but fails with R CMD INSTALL

Minimal example: I have an R package whose sole .R file contains the code

data.table::data.table(iris)[Species == "setosa"]

Expected output:

    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
 ...

This runs fine interactively (and when compiling with knitr, and with r --vanilla).

However, when I run R CMD INSTALL on the package, it fails with:

Error in `[.data.frame`(x, i, j) : object 'Species' not found

Why would this happen only with R CMD INSTALL, and how can I avoid it?

Details:

Package Imports

The package DESCRIPTION file includes the line

Imports: data.table

Transcript of failed 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.

Version information

> 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

Upvotes: 2

Views: 106

Answers (1)

jangorecki
jangorecki

Reputation: 16697

You should always need to maintain NAMESPACE file, not just DESCRIPTION.
import(data.table) to NAMESPACE fill will solve your issue.

Upvotes: 2

Related Questions