please use merge(DT1,DT2,by=vars) or DT1[DT2,on=vars], not merge(DT1,DT2,on=vars)
Created by: tdhock
Hi @philippeverley According to ?merge.data.table man page, there is no "on" argument, but example(plantAreaDensity) has the following code, https://github.com/umr-amap/AMAPVox/blob/e435abe2b7429b8b8f2d66cdffde02e55f81a6eb/R/PlantArea.R#L43
library(AMAPVox)
vxsp <- readVoxelSpace(system.file("extdata", "tls_sample.vox", package = "AMAPVox"))
pad <- plantAreaDensity(vxsp, variable.name = "attenuation_PPL_MLE")
vxsp@data <- merge(vxsp@data, pad, on = list(i, j, k))
Using data.table release version from CRAN, the code above actually works. But using the new version from github master, remotes::install_github("Rdatatable/data.table")
the example code yields the following error:
plntAD> vxsp@data <- merge(vxsp@data, pad, on = list(i, j, k))
Error in merge.data.table(vxsp@data, pad, on = list(i, j, k)) :
object 'i' not found
After discussion with data.table devs https://github.com/Rdatatable/data.table/issues/5532 the fix would be to change your example code to one of the following, which works using data.table github master: (use on argument with square brackets operator, or use by argument with merge)
> dim(vxsp@data[pad, on = list(i, j, k)])
[1] 420 23
> dim(merge(vxsp@data, pad, by = c("i", "j", "k")))
[1] 420 23