0

This line of code works fine when I 'run' it in Rstudio

dt.SSPGDP[, GDP.lag1 :=shift(value), by=c("ISO_code","scenario")]

But when I run devtools::load_all(), I get the following error message

Error in `:=`(GDP.lag1, shift(value)) (from dataManagement.alcohol.R#37) : 
  Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=").

I checked that dt.SSPGDP is in fact a data table.

Any tips on how to fix?

JerryN
  • 2,356
  • 1
  • 15
  • 49
  • Is this in an example? Within in a function in a package? Something else? – Gregor Thomas Mar 14 '16 at 16:09
  • 1
    I guess this in a package and you didn't `import` data.table in your DESCRIPTION and NAMESPACE files. – Roland Mar 14 '16 at 16:30
  • This is a line of code in an R script. I'm trying to figure out how to convert this, and several other scripts, into a package. I have purchased @Hadley Wickham's R Packages book and have been using it to guide my development. The key section on R code workflow, step 2 (Press Ctrl/Cmd-Shift-L) is where the error arises. – JerryN Mar 14 '16 at 22:30
  • My NAMESPACE file only holds `exportPattern("^[^\\.]")`. The DESCRIPTION file has `Imports: data.table, ggplot2, roxygen2, plotrix, plyr, dplyr, openxlsx, splitstackshape, stringi, tidyr, gdxrrw' so it seems like I am in fact importing data.table. – JerryN Mar 14 '16 at 22:37
  • You need to add `import(data.table)` to your NAMESPACE file. – Roland Mar 16 '16 at 08:16
  • Or since you use roxygen2, you can add `#' @import data.table` in your source code. Btw. , it shouldn't be necessary to import roxygen2. – Roland Mar 16 '16 at 08:23

0 Answers0