Read space delimited file where missing values are blank "".
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the issue with fread("fileTest.txt", strip.white = FALSE) using the three-row example and compare the behavior described for data.table 1.10.4 and 1.12.2. Done means space-delimited blank fields are retained as missing values rather than causing an early stop, with regression coverage added for this input.
Written by the indexing model from the issue text.
Description
Example input text file - fileTest.txt:
c1 c2 c3 c4 c5 c6
r1 0 1 2 3 4
r2 0 3 4
r3 0 1 2 3 4
Adding a screenshot to show there are 3 spaces on row r2 between 0 and 3, i.e.: values are missing for c3 and c4.

Using R version 3.4.0 and data.table 1.10.4 (Session info 1), below works as expected:
> fread("fileTest.txt", strip.white = FALSE)
c1 c2 c3 c4 c5 c6
1: r1 0 1 2 3 4
2: r2 0 NA NA 3 4
3: r3 0 1 2 3 4
But fails with R version 3.5.2 and data.table_1.12.2. (Session info 2).
> fread("fileTest.txt", strip.white = FALSE)
c1 c2 c3 c4 c5 c6
1: r1 0 1 2 3 4
Warning message:
In fread("fileTest.txt", strip.white = FALSE) :
Stopped early on line 3. Expected 6 fields but found 4. Consider fill=TRUE and comment.char=. First discarded non-empty line: <<r2 0 3 4>>
Other attempts, all failed:
fread("fileTest.txt")
fread("fileTest.txt", sep = " ")
fread("fileTest.txt", strip.white = FALSE)
fread("fileTest.txt", sep = " ", strip.white = FALSE, na.strings = c("NA", ""))
fread("fileTest.txt", sep = " ", strip.white = FALSE, quote = "")
Note
- I checked the NEWs, SO, Google, couldn't find anything easily relevant info.
- Related SO post: How to read when delimiter is space and missing values are blank?
- read.table works as expected, but my files are huge (millions of rows), hence trying to use fread:
read.table("fileTest.txt", strip.white = FALSE, sep = " ", na.strings = "")
Session info 1
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS/LAPACK: /opt/gridware/apps/intel/compilers_and_libraries_2016.3.210/linux/mkl/lib/intel64_lin/libmkl_gf_lp64.so
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.10.4
loaded via a namespace (and not attached):
[1] compiler_3.4.0
Session info 2
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
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.12.2
loaded via a namespace (and not attached):
[1] compiler_3.5.2 tools_3.5.2
- 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 ·