Repository navigation
fread fails if whitespace before first character #1035
Description
Activity
I am experiencing a similar problem; however, the R session completely aborts in 1.9.4, instead of giving a warning message.
Here is an example illustrating the format of dataset with which I am working:
" 22 4 6 4" " 34 22 34 5" " 6 2 1 4"Each row begins with two white spaces, but the separator for the rest of the values is a single white space.
In version 1.9.4, when I attempted to use fread() in RStudio with my much-larger dataset, I received the following pop-up warning (and the session had to be restarted):
R Session Aborted R encountered a fatal error. The session was terminated.
Using version 1.9.5, I instead received this error message:
Not positioned correctly after testing format of header row. ch=' 'I found this output very confusing, since I had specified that there was no header row (header = FALSE). The verbose=TRUE version of this output is below.
Input contains no \n. Taking this to be a filename to open File opened, filesize is 0.024641 GB. Memory mapping ... ok Detected eol as \r\n (CRLF) in that order, the Windows standard. Positioned on line 1 after skip or autostart This line is the autostart and not blank so searching up for the last non-blank ... line 1 Detecting sep ... ' ' Detected 561 columns. Longest stretch was from line 1 to line 30 Starting data input on line 1 (either column names or first row of data). First 10 characters: 2.571777 Error in fread("UCI HAR Dataset/test/X_test.txt", header = FALSE, verbose = TRUE) : Not positioned correctly after testing format of header row. ch=' 'I am using R version 3.20 ("Full of Ingredients"), with RStudio version 0.98.1103.
I had the same problem. This works:
df <- read.table("./data/train/X_train.txt")but reading the same file with
freaddoes not work and throws me an error:> dt <- fread("./data/train/X_train.txt") Error in fread("./data/train/X_train.txt") : Not positioned correctly after testing format of header row. ch=' 'The file in question can be downloaded from here (66MB's).
Fixed in devel. Please upgrade and test.
@arunsrinivasan Tested. It now works on the file I specified above.
The program I use by default gives output like so:
I first tried with the stable version (1.9.4) and got the following error:
with the development version (1.9.5) I get the following error:
This seems like it would be resolved by #758 or #558 (variable whitespace delimiter)
but just wanted to give another example of a situation where fread currently fails and need to fall back to read.table(sep="") to get the table to read in properly