Column selection without `with = FALSE` is dependent on J expression
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start by reproducing the two iris data.table expressions from the issue and trace how the j expression handles c, paste0, and grep. Done means the column-selection behavior is consistent with the documented syntax, with regression coverage for both examples and the intended with = FALSE or parenthesized alternatives.
Written by the indexing model from the issue text.
Description
(This question is asked on SO with some helpful comments)
Consider the following two examples. The J expresssion is similar in option 1 and option 2, but the results are different: option 1 results in column selection while option 2 is evaluated into a character vector.
> library(data.table)
> iris <- as.data.table(iris)
> # option 1
> iris[, c('Species', paste0(c('Sepal.', 'Petal.'), 'Length'))]
Species Sepal.Length Petal.Length
1: setosa 5.1 1.4
2: setosa 4.9 1.4
3: setosa 4.7 1.3
4: setosa 4.6 1.5
5: setosa 5.0 1.4
---
146: virginica 6.7 5.2
147: virginica 6.3 5.0
148: virginica 6.5 5.2
149: virginica 6.2 5.4
150: virginica 5.9 5.1
> # option 2
> iris[, c('Species', grep('Length', names(iris), value = TRUE))]
[1] "Species" "Sepal.Length" "Petal.Length"
In the comment of the SO post, David Arenburg found that "functions such paste and c are being explicitly searched in the j expression and then set with=FALSE, similar to what happens with .. prefix. grep isn't being searched". From a user's perspective, I think this is very unconvenient. Rather than gusssing what users want to do, it is easier to explicit require users specifiy their needs using with = FALSE or other syntax such as (c(...)) as commented by G. Grothendieck on the SO post.
Here is the sessionInfo:
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.12.2
loaded via a namespace (and not attached):
[1] compiler_3.6.1 tools_3.6.1
- Dominant language
- R
- Stars
- 3.9k
- Forks
- 1.1k
- Avg merge
- 14h 4m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#7853 · 3 comments ·
-
internals
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#6938 · 1 comment ·
-
encoding fread
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#5179 · 8 comments ·
-
documentation programming
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#3199 · 3 comments ·
All issues in Rdatatable/data.table
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·