作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 fread() 使用“\”作为目录分隔符读取一列目录路径时遇到问题。问题是尾随目录分隔符在 fread() 中引发错误。
对于下面的 csv 文件示例,
file,size
"windows\user",123
fread() 和 read.csv() 都同意并且都将\转换为\\
> fread("example.csv")
file size
1: windows\\user 123
但是,对于以下示例,fread() 会出错,而 read.csv() 则正常。
file,size
"windows\user\",123
read.csv() 给出
> read.csv("example.csv")
file size
1 windows\\user\\ 123
虽然 fread() 错误看起来像这样
> fread("example.csv",verbose=TRUE)
Input contains no \n. Taking this to be a filename to open
File opened, filesize is 0.000 GB
File is opened and mapped ok
Detected eol as \r\n (CRLF) in that order, the Windows standard.
Using line 2 to detect sep (the last non blank line in the first 'autostart') ... sep=','
Found 2 columns
First row with 2 fields occurs on line 1 (either column names or first row of data)
All the fields on line 1 are character fields. Treating as the column names.
Count of eol after first data row: 2
Subtracted 1 for last eol and any trailing empty lines, leaving 1 data rows
Error in fread("example.csv", verbose = TRUE) :
' ends field 1 on line 1 when detecting types: "windows\user\",123
我真的很想避免这样做
DT = data.table(read.csv("example.csv"))
如果可能的话。
最佳答案
现已在 GitHub 的 v1.9.3 中修复.
- fread() now accepts trailing backslash in quoted fields. Thanks to user2970844 for highlighting.
$ cat example.csv
file,size
"windows\user\",123
> require(data.table)
> fread("example.csv")
file size
1: windows\\user\\ 123
> read.csv("example.csv")
file size
1 windows\\user\\ 123
>
关于r - fread 和带有尾部反斜杠的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24375832/
我是一名优秀的程序员,十分优秀!