I have a data.table
object on which I'd like to do a simple lookup:
print(class(dt))
print(colnames(dt))
print(dt[region == "UK", ])
In my interactive R session, this chunk of code does exactly what it should.
[1] "data.table" "data.frame"
[1] "region" "site" "visit"
[4] "connectionfailure" "dnserror" "http404"
# ... output ...
In a non-interactive scripted session, I get a confusing error:
[1] "data.table" "data.frame"
[1] "region" "site" "visit"
[4] "connectionfailure" "dnserror" "http404"
Error in `[.data.frame`(x, i, j) : object 'region' not found
It looks like R is dispatching dt[....
to [.data.frame rather than to [.data.table. Any thoughts as to why?
Most likely you don't have library(data.table)
set up in your batch execution. Could be something based on your user profile auto-loading data.table
, but not batch exec. Also, just b/c something has a class data.table
, doesn't mean the package is loaded:
library(data.table)
dt <- data.table(a=1:3)
detach("package:data.table", unload=TRUE)
class(dt)
# [1] "data.table" "data.frame"
setkey(dt, a)
# Error: could not find function "setkey"
library(data.table)
setkey(dt, a)
#works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With