Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带尾随反斜杠的fread和column_R_Data.table - Fatal编程技术网

带尾随反斜杠的fread和column

带尾随反斜杠的fread和column,r,data.table,R,Data.table,我在使用“\”作为目录分隔符读取目录路径列时遇到问题。问题是尾部目录分隔符在fread()中引发错误 对于下面的示例csv文件 file,size "windows\user",123 fread()和read.csv()都同意,并且都将\转换为\\ > fread("example.csv") file size 1: windows\\user 123 但是,对于以下示例,当read.csv()正常时,fread()会给出一个错误 read.csv()提供

我在使用“\”作为目录分隔符读取目录路径列时遇到问题。问题是尾部目录分隔符在fread()中引发错误

对于下面的示例csv文件

file,size
"windows\user",123
fread()和read.csv()都同意,并且都将\转换为\\

> fread("example.csv")
            file size
1: windows\\user  123
但是,对于以下示例,当read.csv()正常时,fread()会给出一个错误

read.csv()提供

而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"))
如果可能的话。

现在已在v1.9.3中修复

  • fread()现在接受带引号字段中的尾随反斜杠。感谢用户2970844的突出显示

碰巧的是,我刚刚在引号内的字段中修复了这个问题以及
\n
。将在准备尝试时添加答案。这确实让人怀疑什么是“正确”修复,因为这是由于
scan
的良好记录行为造成的,与提问者的说法相反,read.csv()的示例并不好文件,大小为“windows\user\”,123`抛出一个错误。@BondedDust
read.csv
对我来说似乎读得很好,同意询问者的意见。我查看了
?scan
-你的意思是什么?
scan
将“\user”解释为ctrl-u后跟“ser”
read.csv(text=“windows\user\”,123”,sep=“,”)
返回:错误:“\u”在以“windows\u”开头的字符串中没有使用十六进制数字。Mac 10.8.5,R 3.1。0@BondedDust这不是
read.csv
,而是解析器。尝试在控制台上单独键入
“windows\user\”,123“
,您会收到相同的错误。要解析,您需要将\加倍。当从包含asker所示内容的文件中读取时,
read.csv(文件名)
有效。这是我在过去几天里看到的两个修复程序。很高兴看到事情这么快就完成了。谢谢。我刚刚编译了github版本,它似乎对我的实际数据有效,但对于我的玩具示例,fread给了我一个空的data.table。我肯定这只是一个小问题,但请尝试
fread(“文件,大小\n\“windows\\user\\”,123\n“
@user2970844我将您的示例包括在测试套件(测试1337和1338)中,所以应该可以。请运行
test.data.table()
并告诉我最后一行。我也粘贴了该命令,并为我工作。我在
“所有1341.3测试…完成正常”
测试1010.1011运行时没有错误,但检查x等于y失败:对不起。。。我从github重新安装,并注意到一个关于dll未被复制的警告。我想这是因为我已经打开了一个现有的R会话。现在一切都按预期工作,我只从winbuilder中得到了您前面提到的两个错误(1010.1011)。非常感谢@MattDowle。
> 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"))
$ 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
>