subsetting inconsitent with NULL vs. ..variable

Open
#4,052 1 comment 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

Reproduce the reported difference between dt[, NULL] and dt[, ..k] using the example in the issue, including k <- NULL. Trace the data.table subsetting entry point for these two expressions and add a regression test covering identical results; done means both expressions return the same result.

Written by the indexing model from the issue text.

Description

consistency programming

when subsetting on a NULL column, data.table returns an expected NULL
however, when subsetting on a NULL variable, data.table returns a Null data.table (0 rows and 0 cols). I would expect both these scenarios to produce identical results

this is an edge case and fairly easy to work around, but logging the inconsistency

> dt <- data.table(A=1:3, B=4:6)
> k <-1:2
> identical(dt[, 1:2], dt[, ..k])
[1] TRUE
> k <- c("A","B")
> identical(dt[, c("A","B")], dt[, ..k])
[1] TRUE
> k <- NULL
> identical(dt[, NULL], dt[, ..k])
[1] FALSE

> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
 [1] IBrokers_0.9-12      doParallel_1.0.14    iterators_1.0.11     foreach_1.5.1        data.table_1.12.6    curl_3.3             rvest_0.3.4          xml2_1.2.2          
 [9] quantmod_0.4-15      TTR_0.23-5           xts_0.11-2           zoo_1.8-6            RODBC_1.3-16         plotrix_3.7-6        RevoUtils_11.0.3     checkpoint_0.4.4    
[17] RevoUtilsMath_11.0.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.2       codetools_0.2-16 lattice_0.20-38  R6_2.3.0         grid_3.5.3       magrittr_1.5     httr_1.4.1       tools_3.5.3      compiler_3.5.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.