Any Way to Force Fread() of Data.Table Not to Stop on Empty Lines

Any way to force fread() of data.table not to stop on empty lines?

Version 1.9.8 of data.table, released 25-NOV-2016, has a new blank.lines.skip option to skip blank lines.

text <- "1,a\n\n2,b\n3,c\n4,a\n\n5,b\n\n6,c"

library(data.table)
fread(text)
## V1 V2
## 1: 2 b
## 2: 3 c
## 3: 4 a
## Warning message:
## In fread("1,a\n\n2,b\n3,c\n4,a\n\n5,b\n\n6,c") :
## Stopped reading at empty line 6 but text exists afterwards (discarded): 5,b

fread(text, blank.lines.skip=TRUE)
## V1 V2
## 1: 1 a
## 2: 2 b
## 3: 3 c
## 4: 4 a
## 5: 5 b
## 6: 6 c

R: Is there a way to fread data.table from file where some (irregular) lines are skipped?

Thanks to Frank,
Solution:

Step 1: Make lines that should be skipped blank (with external editor), then

Step 2: Run fread(text, blank.lines.skip=TRUE)

In R: Send a modified windows command to fread()

Assuming you already have the value stored in newestFile you can use paste0 to construct your string

fread_cmd <- paste0('findstr "." ', newestFile)
fread(fread_cmd, skip = 0, sep = "\n", header = FALSE)

How to stop fread from displaying messages when it is inside trycatch

I tried it, and with data.table 1.9.4 I got:

The system cannot find the path specified.

(Which I guess is the executive summary of your long German sentence ;) )

With data.table version 1.9.6 it works as expected. So just update your packages:

update.packages()

And you should be fine.



Related Topics



Leave a reply



Submit