有什么方法可以强制 data.table 的 fread() 不要停在空行上? [英] Any way to force fread() of data.table not to stop on empty lines?

查看:14
本文介绍了有什么方法可以强制 data.table 的 fread() 不要停在空行上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(问题不再相关,因为 2016 年 11 月 25 日的新版本 data.table - 请参阅下面接受的答案)

(question is not relevant anymore, since new version of data.table of 25-NOV-2016 - see accepted answer below)

所以,我有一张桌子,中间有一些空行.当我尝试使用 fread 打开它时,它会停止,并说 Stopped reading at empty line 10006,但之后文本存在(丢弃).有什么办法可以在不更改数据文件的情况下避免这种情况?

So, I have a table with some empty lines in the middle. When I try to open it with fread, it stops, saying Stopped reading at empty line 10006, but text exists afterwards (discarded). Is there any way to avoid this without changing the data file?

推荐答案

data.table 的 1.9.8 版,于 2016 年 11 月 25 日发布,有一个新的 blank.lines.skip 跳过空行的选项.

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

2,b
3,c
4,a

5,b

6,c"

library(data.table)
fread(text)
##    V1 V2
## 1:  2  b
## 2:  3  c
## 3:  4  a
## Warning message:
## In fread("1,a

2,b
3,c
4,a

5,b

6,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

这篇关于有什么方法可以强制 data.table 的 fread() 不要停在空行上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆