forward operations to vectorised attributes
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Reproduce the data.table examples with the errors package, especially the x[...] subset operation. Start at the errors class's subsetting operator and trace how data.table applies row filters to the column; done means the selected values and their error metadata have matching lengths without warnings or corruption.
Written by the indexing model from the issue text.
Description
The units package stores unit metadata for vectors and arrays as an attribute, and it seems to work fine with data.table:
library(data.table)
library(units)
#> udunits system database from /usr/share/udunits
(DT <- data.table(x = set_units(1:5, m), y = set_units(2, s)))
#> x y
#> 1: 1 m 2 s
#> 2: 2 m 2 s
#> 3: 3 m 2 s
#> 4: 4 m 2 s
#> 5: 5 m 2 s
DT[, z := x/y]
DT
#> x y z
#> 1: 1 m 2 s 0.5 m/s
#> 2: 2 m 2 s 1.0 m/s
#> 3: 3 m 2 s 1.5 m/s
#> 4: 4 m 2 s 2.0 m/s
#> 5: 5 m 2 s 2.5 m/s
DT[x > set_units(3, m)]
#> x y z
#> 1: 4 m 2 s 2.0 m/s
#> 2: 5 m 2 s 2.5 m/s
Similarly, the errors package stores uncertainty metadata for vectors and arrays, but this time the attribute is a vector of errors. Some operations are correctly forwarded:
library(errors)
(DT <- data.table(x = set_errors(1:5, 1:5/10), y = set_errors(2, 0.1)))
#> x y
#> 1: 1.0(1) 2.0(1)
#> 2: 2.0(2) 2.0(1)
#> 3: 3.0(3) 2.0(1)
#> 4: 4.0(4) 2.0(1)
#> 5: 5.0(5) 2.0(1)
DT[, z := x/y]
DT
#> x y z
#> 1: 1.0(1) 2.0(1) 0.50(6)
#> 2: 2.0(2) 2.0(1) 1.0(1)
#> 3: 3.0(3) 2.0(1) 1.5(2)
#> 4: 4.0(4) 2.0(1) 2.0(2)
#> 5: 5.0(5) 2.0(1) 2.5(3)
As you can see above, errors are propagated for the division. But others not:
(DT.subset <- DT[x > set_errors(3)])
#> Warning: In '>' : boolean operators not defined for 'errors' objects,
#> errors dropped
#> Warning in exponent + value_digits: longer object length is not a multiple
#> of shorter object length
#> Warning in (scientific | (exponent > 4 + scipen | exponent < -3 - scipen))
#> & : longer object length is not a multiple of shorter object length
#> Warning in exponent + value_digits: longer object length is not a multiple
#> of shorter object length
#> Warning in (scientific | (exponent > 4 + scipen | exponent < -3 - scipen))
#> & : longer object length is not a multiple of shorter object length
#> Warning in exponent + value_digits: longer object length is not a multiple
#> of shorter object length
#> Warning in (scientific | (exponent > 4 + scipen | exponent < -3 - scipen))
#> & : longer object length is not a multiple of shorter object length
#> Error in dimnames(x) <- dn: length of 'dimnames' [1] not equal to array extent
The errors class does implement the subsetting operator, but it's not getting called, so the resulting errors object is corrupted (more errors than values):
DT$x
#> Errors: 0.1 0.2 0.3 0.4 0.5
#> [1] 1 2 3 4 5
DT.subset$x
#> Errors: 0.1 0.2 0.3 0.4 0.5
#> [1] 4 5
- 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 ·