Using setDT after loading
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Reproduce the supplied R script using setDT, setalloccol, and := after save/load, starting from the documented behavior of these entry points. Determine whether the observed mutation is expected or a data.table defect, then add a focused regression test or clarify the behavior in the project’s documentation.
Written by the indexing model from the issue text.
Description
Thanks for the data.table package. I'm a new user and I've found it useful so far, but one thing I'm having trouble with is using setDT or setalloccol after loading from disk, in order to be able to use :=. I use those functions but := still appears not to work. I may be misunderstanding how those functions are meant to be used.
Example:
library(data.table)
L <- vector("list", length = 2)
names(L) <- c("A1", "A2")
for (A in c("A1", "A2")) {
L[[A]] <- vector("list", length = 2)
names(L[[A]]) <- c("B1", "B2")
}
for (A in c("A1", "A2")) {
for (B in c("B1", "B2")) {
L[[A]][[B]] <- data.table(u = 1:3, v = 2:4)
}
}
L[["A1"]][["B1"]][, w := 0] # this works
L
## $A1
## $A1$B1
## u v w
## 1: 1 2 0
## 2: 2 3 0
## 3: 3 4 0
## $A1$B2
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
## $A2
## $A2$B1
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
## $A2$B2
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
save(L, file = "~/L.RData")
rm(L)
load("~/L.RData")
for (A in c("A1", "A2")) {
for (B in c("B1", "B2")) {
setDT(L[[A]][[B]])
}
}
L[["A1"]][["B1"]][, x := 99]
L # x doesn't appear
## $A1
## $A1$B1
## u v w
## 1: 1 2 0
## 2: 2 3 0
## 3: 3 4 0
## $A1$B2
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
## $A2
## $A2$B1
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
## $A2$B2
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
# Try using setalloccol instead of setDT
for (A in c("A1", "A2")) {
for (B in c("B1", "B2")) {
setalloccol(L[[A]][[B]])
}
}
L[["A1"]][["B1"]][, x := 99]
L # x doesn't appear
## $A1
## $A1$B1
## u v w
## 1: 1 2 0
## 2: 2 3 0
## 3: 3 4 0
## $A1$B2
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
## $A2
## $A2$B1
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
## $A2$B2
## u v
## 1: 1 2
## 2: 2 3
## 3: 3 4
sessionInfo()
## R version 4.0.3 (2020-10-10)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
## 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.13.4
## loaded via a namespace (and not attached):
## [1] compiler_4.0.3
Please let me know if I've misunderstood something. Thank you.
- 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 ·