Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data.table corrupts variables by failing to check NAMED before modifying a vector #2984

Closed
radfordneal opened this issue Jul 23, 2018 · 0 comments · Fixed by #3071
Closed
Assignees
Labels
Milestone

Comments

@radfordneal
Copy link

radfordneal commented Jul 23, 2018

data.table can fail to check that NAMED is 0 before changing a vector, thereby corrupting variables. Below is a specific example, but I suspect that the problem occurs widely in the source code for data.table (based on various attempts with various versions of data.table to get it to work with pqR).

This example is adapted from data.table test number 430 (which crashes when run in pqR because in pqR 3L is a read-only constant). Changing the test to use a variable set to 3L rather than the constant 3L reveals the problem in R-3.5.1 as well (and I expect in all versions of R).

library(data.table)
# data.table 1.11.4  Latest news: http://r-datatable.com
DT <- data.table(a = factor(c("A", "Z")), b = 1:4)
a <- 3L
DT[1,1]<- a 
#  Warning message:
#  In `[<-.data.table`(`*tmp*`, 1, 1, value = NA_integer_) :
#    RHS contains 3 which is outside the levels range ([1,2]) of column 1, NAs generated
a
# [1] NA     ---- This should still be3L, not changed to NA!
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.11.4

loaded via a namespace (and not attached):
[1] compiler_3.5.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants