带有反斜杠的fread和column

Jac*_*vin 3 r data.table

我有一个问题,fread()使用"\"作为目录分隔符读取一列目录路径.问题是尾随目录分隔符在fread()中引发错误.

对于以下示例csv文件,

file,size
"windows\user",123
Run Code Online (Sandbox Code Playgroud)

fread()和read.csv()都同意并且都将\转换为\\

> fread("example.csv")
            file size
1: windows\\user  123
Run Code Online (Sandbox Code Playgroud)

但是,对于以下示例,fread()在read.csv()没问题时给出错误.

file,size
"windows\user\",123
Run Code Online (Sandbox Code Playgroud)

read.csv()给出

> read.csv("example.csv")
             file size
1 windows\\user\\  123
Run Code Online (Sandbox Code Playgroud)

虽然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
Run Code Online (Sandbox Code Playgroud)

我真的想避免这样做

DT = data.table(read.csv("example.csv"))
Run Code Online (Sandbox Code Playgroud)

如果可能的话.

Mat*_*wle 5

现在已在GitHub上的v1.9.3中修复.

  • fread()现在接受引用字段中的尾部反斜杠.感谢user2970844突出显示.
$ 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
> 
Run Code Online (Sandbox Code Playgroud)