fread fails for properly quoted \n in file with \r as EOL
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the minimal example with fread() and the linked dt-test.csv input, then compare its parsing with data.table 1.10.4-3. Trace the fread() handling of carriage returns, quoted fields, and row boundaries. Done means the ^M separators create rows while carriage returns inside quoted cells do not, matching the expected four-row output.
Written by the indexing model from the issue text.
Description
I described this on stackoverflow, Hugh suggested it might be a valid issue to report here (https://stackoverflow.com/questions/50918972/data-table-fread-does-not-see-m-as-new-line-any-more)
This is a new problem with data.table 1.11.4, did not occur in 1.10.4-3.
Data sets distributed from Qualtrics sometimes have both "^M" to mark new lines and also there are "naked" carriage returns in the middle of data cells. This confuses R read.csv horribly, we changed over to fread and it has worked in past. Now it is not working. In all of the cases I have tested, the problem is in row 2 of the data frame where the questions are repeated and when the Qualtrics user includes a carriage return in their cut/paste, then that return is preserved in the data. I made an MRE data set, http://pj.freefaculty.org/scraps/dt-test.csv
Another element in this mess is the new-ish Excel style of quotes for character variables, which do not include quotation marks unless absolutely necessary. We see some cell entries with quotes and others without in the row 2 information.
I do not want to preserve the carriage returns that are in the middle of the cells. I want the "^M" to be seen as new lines.
# Minimal reproducible example
library(data.table)
fread("http://pj.freefaculty.org/scraps/dt-test.csv")
The output is as follows.
Note that the things that show as "^M" in Emacs are seen as "\r" in fread error message:
id,y,x1,x2\rRespondentidentification, "An
1: variable", "Working
2: input", "more
outcome
1: on
2: input"\rResp1,33,22,33\rResp2,31,19,32
Warning message:
In fread("http://pj.freefaculty.org/scraps/dt-test.csv") :
Found and resolved improper quoting in first 100 rows. If the fields are not quoted (e.g. field separator does not appear within any field), try quote="" to avoid this warning.
Desired result, which happened in previous version of data.table, is a new data object, with the CSV rows separated by the "^M" thing and ignoring the carriage returns in the middle of the input data for row 2.
id,y,x1,x2
Respondentidentification, "An outcome variable", "Working on input", "more input"
Resp1,33,22,33
Resp2,31,19,32
I expect these will be all character because of the questions in row 2.
I am not allowed to publish the real Qualtrics data set in this forum, but if one of the data.table developers is willing to write me at pauljohn@ku.edu, I'll email a copy if you will agree not to redistribute. But I do believe the MRE is representative.
# Output of sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04 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
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.11.4
loaded via a namespace (and not attached):
[1] compiler_3.4.4
- 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 ·