0

I have a custom package but I'm having trouble using data.table inside functions. I've included data.table in the Imports file: Using data.table package inside my own package

If I save this funciton in the global enviroment it runs no-problem but now when called from the pacakge.

The error is:

Error in :=(shapeId, paste(shape1, shape3, sep = "-")) : Check that is.data.table(DT) == TRUE. Otherwise, := and :=(...) are defined for use in j, once only and in particular ways. See help(":=")

However if I go into browser() mode to where this problem occurs, I find that running is.data.table(res) returns TRUE: For replication:

res = structure(list(shape1 = c("oh", "sd", "tx", "tx", "tx", "tx"), 
    shape3 = c("pike", "aurora", "kendall", "kendall", "kendall", 
    "kendall")), .Names = c("shape1", "shape3"), row.names = c(NA, 
6L), class = c("data.table", "data.frame"))

and then run

res[, shapeId := paste(shape1, shape3, sep = '-')]

triggers the error . Even though

Browse[2]>is.data.table(res)
Browse[2]>TRUE
Uwe
  • 41,420
  • 11
  • 90
  • 134
Rafael
  • 3,096
  • 1
  • 23
  • 61
  • Use `setDT(res)` after you recreated `res` with `structure(list ...` – Jaap May 31 '18 at 16:17
  • that structure was the result of a `dput(res)` after running `setDT(res)`, `res` is already a `data.table`. – Rafael May 31 '18 at 16:18
  • I know. But I would like to see what happens when you run `setDT(res)[, shapeId := paste(shape1, shape3, sep = '-')]`. I suspect your error will go away. – Jaap May 31 '18 at 16:23
  • 2
    Please check out Jan's recent vignette: https://cran.r-project.org/web/packages/data.table/vignettes/datatable-importing.html – MichaelChirico May 31 '18 at 16:27
  • the error is still there – Rafael May 31 '18 at 17:10
  • I can't reproduce the error. Could include a self contained example that reproduces the error? – Jaap May 31 '18 at 19:08

0 Answers0