I have a weird behavior, when running my R program on another machine.
When I try to run a data.table join df1[df2]
I get the error message
Error in `[.default`(x, i) : invalid subscript type 'list'
I assume that for some reason the R environment on the other machine does not find the data.table bracket function (Although I have loaded the library there).
To force R to use the bracket from data.table I would like to call the bracket function explicitly, but I can't find out how.
Here what I've tried
library(data.table)
df1 <- data.frame(a = c("a1","a2","a3"), n = c(1,2,3), b = c(T,T,T))
df2 <- data.frame(a = c("a1","a2","a3"), n = c(1,2,3), b = c(F,T,F))
df1 <- data.table(df1)
df2 <- data.table(df2)
setkey(df1,a,n,b)
setkey(df2,a,n,b)
df1[df2] # produces `[.default`(x, i) : invalid subscript type 'list'
# my tries to call `[.data.table` explicitly all produce errors
`[.data.table`(df1, df2)
data.table::`[.data.table`(df1, df2)
data.table::`[`(df1, df2)
How can I use the bracket function from the data.table package explicitly?
EDIT:
OK, I'm trying to find the root cause of the error. I'm using R version 3.2.1,
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.9.2 mypackage_1.0 ROracle_1.1-10 DBI_0.2-7
loaded via a namespace (and not attached):
[1] plyr_1.8.1 reshape2_1.4 Rcpp_0.11.2 stringr_0.6.2
is.data.table
gives TRUE
on both, df1 and df2 just before calling df1[df2]
(I'm debugging through the code).
The function that contains the codeline df1[df2]
is called inside mypackage_1.0 (A package I'm developing). I have noticed, that if I run the code line by line, instead of calling my package function and debugging it, the code works as expected. So I assume there is something wrong with the package. In the DESCRIPTION file I only import the package data.table under "Suggests". Might it be related to that?