Using `..` in j have limitations in expression, RHS of assignment
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the two examples in the issue, covering expressions with two .. references and the combination of (col2) := ..col2 * 2. Trace how data.table evaluates .. in j, expressions, and assignment, then establish and test the intended behavior or document the supported limitation.
Written by the indexing model from the issue text.
Description
I tried to search if this was reported before, but .. is ignored in github search so I cannot really search this problem.
- we can use
..in j to access column name saved in variable, but it will fail with an expression involving two..reference.
dt <- data.table(mtcars)
col1 <- "hp"
col2 <- "cyl"
# this looks like returned the data.table that have col1 removed.
# I knew there is usage of `-..col1` to remove that column,
# but this is confusing and make below problematic
dt[, ..col1 - ..col2]
> dt[, ..col1 - ..col2]
mpg cyl disp drat wt qsec vs am gear carb
1: 21.0 6 160.0 3.90 2.620 16.46 0 1 4 4
2: 21.0 6 160.0 3.90 2.875 17.02 0 1 4 4
3: 22.8 4 108.0 3.85 2.320 18.61 1 1 4 1
# adding () doesn't fix this
dt[, (..col1) - (..col2)]
- we can use
()in LHS of assignment,..in RHS of assignment, but not together
dt[, (col2) := 8]
dt[, ..col2]
dt[, (col2) := ..col2 * 2]
# Error in ..col2 * 2 : non-numeric argument to binary operator
So is .. supposed to be used only as itself and cannot be used in any expression?
I knew dt[[col1]] will always work, but that will not work when we also are using selective condition in i at the same time.
- 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 ·