Subsetting 1row DT with | (or) plus assigning NA with := changes column class

Open
#3,243 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by running the minimal reproducible example from the issue with data.table 1.11.8, comparing the single-condition assignment with the condition using |. Trace the assignment path for b:=NA and verify that the column remains integer after the OR subset, matching the behavior of the first assignment.

Written by the indexing model from the issue text.

Description

consistency

# Minimal reproducible example

library(data.table)

dt <- data.table(a="This", b=as.integer(NA))
class(dt$b) #Class is correctly set to integer.

dt[a=="This", b:=NA]
class(dt$b) #Class is still integer.

dt[a=="This" | a=="That", b:=NA]
class(dt$b) #Class has incorrectly changed to logical.

# Output of sessionInfo()

R version 3.5.1 (2018-07-02)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252

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

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

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

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.