data.table-fread(),在第一个单元格中有多个引号的读表

时间:2014-09-01 15:05:38

标签: r data.table fread

我有很多大表,起始单元格可能包含多个引号,如下所示:

的test.txt -

"abc"" xyz""",123
mno,456

现在fread("test.txt",sep=",",header=F)会引发错误

Error in fread("123.txt", sep = ",", header = F) : 
  Unexpected character (" nxy) ending field 1 of line 1

它读到了这一点 的test2.txt -

qwe,999
"abc"" nxyz""",123
mno,456

尽管fread("test2.txt",sep=",",header=F)正确。

我需要让它以另一种方式运行。任何解决方案?

@Arun,我尝试从github安装data.table v1.9.3但是出现了以下错误,有什么想法吗?感谢。

> remove.packages("data.table")
Removing package from ‘C:/Users/sidpat/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)
> install_github("Rdatatable/data.table")
Installing github repo data.table/master from Rdatatable
Downloading master.zip from https://github.com/Rdatatable/data.table/archive/master.zip
Installing package from C:\Users\SIDPAT\AppData\Local\Temp\RtmpUBzt2K/master.zip
Installing data.table
"C:/PROGRA~1/R/R-30~1.3/bin/x64/R" --vanilla CMD build  \
  "C:\Users\sidpat\AppData\Local\Temp\RtmpUBzt2K\devtoolsc241bb5e2e\data.table-master"  \
  --no-manual --no-resave-data 

* checking for file 'C:\Users\sidpat\AppData\Local\Temp\RtmpUBzt2K\devtoolsc241bb5e2e\data.table-master/DESCRIPTION' ... OK
* preparing 'data.table':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to build vignettes
Warning: running command '"C:/PROGRA~1/R/R-30~1.3/bin/x64/Rcmd.exe" INSTALL -l "C:\Users\SIDPAT\AppData\Local\Temp\RtmpKyohpy\Rinst1ee42c4a1653" --no-multiarch "C:/Users/sidpat/AppData/Local/Temp/RtmpKyohpy/Rbuild1ee425057481/data.table"' had status 1
      -----------------------------------
* installing *source* package 'data.table' ...
** libs
Warning: running command 'make -f "Makevars" -f "C:/PROGRA~1/R/R-30~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-30~1.3/share/make/winshlib.mk" SHLIB="data.table.dll" WIN=64 TCLBIN=64 OBJECTS="assign.o bmerge.o chmatch.o dogroups.o fastmean.o fastradixdouble.o fastradixint.o fcast.o fmelt.o forder.o frank.o fread.o gsumm.o ijoin.o init.o rbindlist.o reorder.o uniqlist.o vecseq.o wrappers.o"' had status 127
ERROR: compilation failed for package 'data.table'
* removing 'C:/Users/SIDPAT/AppData/Local/Temp/RtmpKyohpy/Rinst1ee42c4a1653/data.table'
      -----------------------------------
ERROR: package installation failed
Error: Command failed (1)

1 个答案:

答案 0 :(得分:0)

你试过df <- read.csv("test.txt", sep=",", header=F, quote="")吗?然后,您可以将结果数据帧转换为数据表dt <- data.table(df)

这里有关于恐惧和不平衡报价的讨论: data.table::fread and Unbalanced "

我假设test2.txt有效,因为该字段不以引号开头。