A very bad usage of set leads to the systematic crash of the Rsession.
# minimal reproductible example :
library(data.table)
n<-1e6
dt<-
data.table(
fact=factor(rep("A",n)),
case=rep(TRUE,n),
coeff=rep(5,n))
x<-"fact"
set(
dt,
i= which(dt$case==TRUE),
j= "fact",
value=dt[(case),..x]*dt$coeff
)
For the crash to happen :
- n should be big (n=1e4 : no crash, n=1e5 : crash)
dt$fact needs to be a factor
- argument
i needs to be used in set
- argument
j needs to be exactly "fact" (needs to overwrite column "fact")
- one should use
..x and not "fact" in dt[(case),..x]
# Output of sessionInfo()
sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)Matrix products: defaultlocale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
[3] LC_MONETARY=French_France.1252 LC_NUMERIC=C
[5] LC_TIME=French_France.1252attached base packages:
[1] stats graphics grDevices utils datasets methods baseother attached packages:
[1] data.table_1.13.0loaded via a namespace (and not attached):
[1] compiler_4.0.0 tools_4.0.0
A very bad usage of
setleads to the systematic crash of the Rsession.#minimal reproductible example:For the crash to happen :
dt$factneeds to be afactorineeds to be used insetjneeds to be exactly "fact" (needs to overwrite column "fact")..xand not "fact" indt[(case),..x]#Output of sessionInfo()