X[Y] join synatx not adding columns when called inside a function after having substituted names of X
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by running the reproducible function f(X) and the X[Y, x := i.x, on = "b"] join shown in the issue, comparing behavior before and after names(X) is changed. Trace how the join and column assignment handle the renamed table, then add a regression test showing that x is retained in X after f(X) returns.
Written by the indexing model from the issue text.
Description
Here a column 'x' is joined to the table X inside a function. However, when setting names(X) the way it's done below, the 'x' column is not actually added to X. Removing the name-change line, however, produces the desired output.
require(data.table)
# function that left-joins an 'x' column to X
f <- function(X){
Y <- data.table(x = runif(3), b = letters[1:3])
X[Y, x := i.x, on = "b"]
}
X <- data.table(a = runif(10), b = letters[1:10])
#------ changing names of X like this makes it so that 'x' disappears after f(X) has returned
names(X) <- gsub("a", "c", names(X))
#--------------------------------------------------------------------------------------------------------
f(X)
print(X)
## 'x' column is missing:
# c b
# 1: 0.07323440 a
# 2: 0.75673707 b
# 3: 0.01909958 c
# 4: 0.12090685 d
# 5: 0.45551750 e
# 6: 0.21110334 f
# 7: 0.81974756 g
# 8: 0.40734517 h
# 9: 0.24263204 i
# 10: 0.38344870 j
> 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/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=nb_NO.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=nb_NO.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=nb_NO.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=nb_NO.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] MASS_7.3-51.1 zoo_1.8-6 compiler_3.6.1 magrittr_1.5 strucchange_1.5-1 sandwich_2.5-1 tools_3.6.1
[8] nlme_3.1-140 urca_1.3-0 grid_3.6.1 vars_1.5-3 lmtest_0.9-37 RKlav_0.2 lattice_0.20-38
- 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 ·