The following code generates data files where each row has a different number of columns. The option fill=TRUE
appears to work only when a certain character limit is reached. For instance compare lines 1-3 with lines 9-11, noting that both of these examples work as expected. How can I read the entirety of notworking1.dat
with fill=TRUE
enabled and not just the first 100 rows?
for (i in seq(1000,1099,by=1))
cat(file="working1.dat", c(1:i, "\n"), append = TRUE)
df <- fread(input = "working1.dat", fill=TRUE)
for (i in seq(1000,1101,by=1))
cat(file="notworking1.dat", c(1:i, "\n"), append = TRUE)
df <- fread(input = "notworking1.dat", fill=TRUE)
for (i in seq(1,101,by=1))
cat(file="working2.dat", c(1:i, "\n"), append = TRUE)
df <- fread(input = "working2.dat", fill=TRUE)
The following solution will also fail
df <- fread(input = "notworking1.dat", fill=TRUE, col.names=paste0("V", seq_len(1101)))
Warning Message received:
Warning message: In data.table::fread(input = "notworking1.dat", fill = TRUE) : Stopped early on line 101. Expected 1099 fields but found 1100. Consider fill=TRUE and comment.char=. First discarded non-empty line: <<1 2 3 4 ...