fread and a quoted multi-line column value

巧了我就是萌 提交于 2019-12-18 08:46:10

问题


> fread('col1,col2\n')
Empty data.table (0 rows) of 2 cols: col1,col2
> fread('col1,col2\n5,4')
   col1 col2
1:    5    4
> fread('col1,col2\n5,"4\n3"')
Error in fread("col1,col2\n5,\"4\n3\"") : 
  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.


回答1:


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 \n 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



来源:https://stackoverflow.com/questions/21006661/fread-and-a-quoted-multi-line-column-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!