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

R crashes when assigning a list with a matrix to a subset of a data.table #4678

Closed
kevinvzandvoort opened this issue Aug 18, 2020 · 1 comment · Fixed by #4350
Closed

R crashes when assigning a list with a matrix to a subset of a data.table #4678

kevinvzandvoort opened this issue Aug 18, 2020 · 1 comment · Fixed by #4350
Labels
non-atomic column e.g. list columns, S4 vector columns
Milestone

Comments

@kevinvzandvoort
Copy link

Assigning a list with a matrix to a subset of a data.table causes R to crash with the error message:

*** caught segfault ***
address 0x4, cause 'memory not mapped'

I am using R 3.6.3 on platform x86_64-pc-linux-gnu. This happened both when using data.table 1.12.8 and 1.13.0.

Reproducible example:
library(data.table)

y <- data.table(i=c(1:10), m=list(matrix(c(0.1:0,4), 2, 2)))
x <- list(matrix(c(1.1:1.4), 2, 2))

Assignment without subsetting works:
y[, m := x]
y[, "m"] <- x

But when subsetting rows and performing the same operation R terminates after attempting to print the object
y[i>6, m := x]
y

# Output of sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
[1] LC_CTYPE=en_GB.UTF-8
[2] LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8
[4] LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8
[6] LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8
[8] LC_NAME=C
[9] LC_ADDRESS=C
[10] LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8
[12] LC_IDENTIFICATION=C

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

loaded via a namespace (and not attached):
[1] compiler_3.6.3 tools_3.6.3

@tlapak
Copy link
Contributor

tlapak commented Aug 18, 2020

Fixed by #4350. The matrix is unrelated btw. Though this currently requires you to wrap x in an additional list to get the recycling you're probably expecting:

y <- data.table(i=c(1:10), m=list(matrix(c(0.1:0,4), 2, 2)))
x <- list(matrix(1:4, 2, 2))
y[i>6, m := x]
# Warning message:
# In `[.data.table`(y, i > 6, `:=`(m, x)) :
#   2 column matrix RHS of := will be treated as one vector

y
#        i               m
#    <int>          <list>
# 1:     1 0.1,4.0,0.1,4.0
# 2:     2 0.1,4.0,0.1,4.0
# 3:     3 0.1,4.0,0.1,4.0
# 4:     4 0.1,4.0,0.1,4.0
# 5:     5 0.1,4.0,0.1,4.0
# 6:     6 0.1,4.0,0.1,4.0
# 7:     7               1
# 8:     8               2
# 9:     9               3
# 10:   10               4

y[i>6, m := .(x)]
y
#        i               m
#    <int>          <list>
# 1:     1 0.1,4.0,0.1,4.0
# 2:     2 0.1,4.0,0.1,4.0
# 3:     3 0.1,4.0,0.1,4.0
# 4:     4 0.1,4.0,0.1,4.0
# 5:     5 0.1,4.0,0.1,4.0
# 6:     6 0.1,4.0,0.1,4.0
# 7:     7         1,2,3,4
# 8:     8         1,2,3,4
# 9:     9         1,2,3,4
# 10:   10         1,2,3,4

@tlapak tlapak linked a pull request Aug 18, 2020 that will close this issue
@jangorecki jangorecki added the non-atomic column e.g. list columns, S4 vector columns label Aug 19, 2020
@mattdowle mattdowle added this to the 1.14.1 milestone May 18, 2021
@jangorecki jangorecki modified the milestones: 1.14.9, 1.15.0 Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-atomic column e.g. list columns, S4 vector columns
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants