UTF encoding in .SDcols causes error when using 'by' argument if there are any accents.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by running the reproducible example with data.table 1.13.4 and the UTF-8 column name "á", focusing on the two queries using by and .SDcols. Trace the relevant .SD and grouping handling; done means both queries run without an encoding error and produce the same result as the unencoded example.
Written by the indexing model from the issue text.
Description
I am working with database that has accentuated characters in the column names and came across an error when trying to use some data.table features. As far as I can tell, the problem lies in that when reading and writing the data I must declare either fwrite(..., bom = T) or fread(..., encoding = "UTF-8"). It is vital to have the correct characters in the column names as well as in each observation and so the data must be imported using UTF-8. Bellow is a reproducible example of my problem. I believe this to be a bug as data.table is able to manage diacritics correctly (as shown in the desired result). It just seems to be misbehaving when using the encoding = "UTF-8" option.
I looked at the dev and found no reference to special characters, or .SDcols handling of diacritics. I also looked at the 1.13.7 milestone page and found nothing relating to this topic either. I tried searching in stack overflow and the queries I came up with did not result in any similar issues.
Thanks.
# Reproducible Example
library(data.table)
set.seed(1)
eg <- data.table("year" = rep(2010:2016, each = 3),
"á" = sample(c(1:3, NA), 21, replace = T))
eg2 <- copy(eg)
# Encode variable names in UTF-8
names(eg2) <- enc2utf8(names(eg2))
# These will result in an error
eg2[, lapply(.SD, function(x) uniqueN(x)), by = "year"]
eg2[, lapply(.SD, function(x) uniqueN(x)), by = "year", .SDcols = "á"]
# Desired output
eg[, lapply(.SD, function(x) uniqueN(x)), by = "year"]
# Output of sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.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 tools_4.0.3
- 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 ·