Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

r - fread and a quoted multi-line column value

> fread('col1,col2
')
Empty data.table (0 rows) of 2 cols: col1,col2
> fread('col1,col2
5,4')
   col1 col2
1:    5    4
> fread('col1,col2
5,"4
3"')
Error in fread("col1,col2
5,"4
3"") : 
  Unbalanced quote (") observed on this line: 3"
> 

read.csv can import this csv as long as the value that spans multiple lines is wrapped in quotes.

Should fread be able to import it as well? Using read.csv is actually fine for my use case. I can just convert the resulting data frame into a data table. But I just wanted to make sure that not having this functionality was a design decision, and not something that just wasn't yet tested.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UPDATE: Now fixed in v1.9.3 on GitHub :

  • fread() now accepts line breaks inside quoted fields. Thanks to Clayton Stanley for highlighting.



This error has been reported before and it's on the list to do. But what's new here is the inside the quotes. I hadn't realised that was a use case giving rise to the error.

Many thanks for reporting. It'll be fixed.

Similar question but not exactly the same here :

data.table::fread and Unbalanced "

and the bug report is here :

https://r-forge.r-project.org/tracker/?group_id=240&atid=975&func=detail&aid=2694


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...