Assigning to list column in single row table changes column type.

Open
#4,568 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start by running the minimal reproducible R example in issue #4568 with data.table 1.12.8, comparing one-row and two-row list columns. Trace the single-row assignment path and add a regression test showing that assigning through dt$a[[1]] preserves a list column; done means is.list(dt$a) remains TRUE for the one-row case.

Written by the indexing model from the issue text.

Description

non-atomic column

When assigning to an element of a list column a using e.g. dt$a[[1]], the column remains a list-column only if the table has more than one row. If the table has one single row, the column is converted to an atomic type.

Minimal reproducible example
library("data.table")
dt <- data.table(a = list(1, 2))
dt$a[[1]] <- 1
is.list(dt$a)
#> [1] TRUE  # as expected!
dt <- data.table(a = list(1))
dt$a[[1]] <- 1
is.list(dt$a)
#> [1] FALSE  # unlike expected!
Output of sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 31 (Thirty One)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8    
 [5] LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=en_US.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

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

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

loaded via a namespace (and not attached):
[1] compiler_3.6.3
Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.