【发布时间】:2015-10-22 08:39:27
【问题描述】:
如果文件很大(约 30 GB),我会分块读取,并注意到大部分时间都花在了对整个文件执行行计数上。
Read 500000 rows and 49 (of 49) columns from 28.250 GB file in 00:01:09
4.510s ( 7%) Memory map (rerun may be quicker)
0.000s ( 0%) sep and header detection
53.890s ( 79%) Count rows (wc -l)
0.010s ( 0%) Column type detection (first, middle and last 5 rows)
0.120s ( 0%) Allocation of 500000x49 result (xMB) in RAM
9.780s ( 14%) Reading data
0.000s ( 0%) Allocation for type bumps (if any), including gc time if triggered
0.000s ( 0%) Coercing data already read in type bumps (if any)
0.060s ( 0%) Changing na.strings to NA
68.370s Total
是否可以指定 fread 在我每次读取块时不进行完整的行计数,或者这是一个必要的步骤?
编辑: 这是我正在运行的确切命令:
fread(pfile, skip = 5E6, nrows = 5E5, sep = "\t", colClasses = rpColClasses, na.strings = c("NA", "N/A", "NULL"), head = FALSE, verbose = TRUE)
【问题讨论】:
-
你可以试试低层
scan。 -
不清楚您运行的是哪个版本。我认为它是 1.9.4。你能试试1.9.5吗? This commit 似乎完全按照您提到的方式处理它。
-
我不相信
fread不再使用wc -l,您仍然可以访问该文件吗?可以重新运行吗?
标签: r data.table