When I try to use shift
in data.table
, when package rasterVis
is already loaded, I get this error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘shift’ for signature ‘"integer"’
For example, this works flawlessly:
library(data.table)
# library(rasterVis)
DT <- data.table(a = 1:50)
DT[, lagged.a := shift(a, 12, type = 'lag')]
but this not, even if I try to unload the package:
library(data.table)
library(rasterVis)
DT <- data.table(a = 1:50)
DT[, lagged.a := shift(a, 12, type = 'lag')] # ERROR
detach('package:rasterVis', unload = TRUE) # or
unloadNamespace(rasterVis)
library(data.table) # I reload data.table, but still nothing
DT[, lagged.a := shift(a, 12, type = 'lag')] # still ERROR
I can obviously run the shift related lines to a new R environment, but I am curious if I can fix it without doing so.