任何方式强制fread()data.table不停止在空行? [英] Any way to force fread() of data.table not to stop on empty lines?

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

问题描述

(非常简单的问题 - 但我在 fread help中找不到答案)...

(very simple question - but I couldn't find an answer in fread help)...

所以,我有一个表中间有一些空行。当我尝试用 fread 打开它时,它停止,说停止读取空行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?

推荐答案

版本1.9.8的data.table ,发布25-NOV-2016,有一个新的 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\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

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

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