R data.table大小和内存限制

时间:2015-01-29 20:17:03

标签: r data.table

我有一个15.4GB的R data.table对象,有2900万条记录和135个变量。我的系统& R信息如下:

Windows 7 x64 on a x86_64 machine with 16GB RAM."R version 3.1.1 (2014-07-10)" on "x86_64-w64-mingw32" 

我收到以下内存分配错误(参见图片)

enter image description here

我将内存限制设置如下:

#memory.limit(size=7000000)
#Change memory.limit to 40GB when using ff library
memory.limit(size=40000)

我的问题如下:

  1. 我应该将内存限制更改为7 TB
  2. 将文件分成多个块并执行此过程?
  3. 还有其他建议吗?

2 个答案:

答案 0 :(得分:7)

尝试分析您的代码以确定哪些语句导致“浪费RAM”:

# install.packages("pryr")
library(pryr) # for memory debugging

memory.size(max = TRUE) # print max memory used so far (works only with MS Windows!)
mem_used()
gc(verbose=TRUE) # show internal memory stuff (see help for more)

# start profiling your code
Rprof( pfile <- "rprof.log", memory.profiling=TRUE) # uncomment to profile the memory consumption

# !!! Your code goes here

# Print memory statistics within your code whereever you think it is sensible
memory.size(max = TRUE)
mem_used()
gc(verbose=TRUE)

# stop profiling your code
Rprof(NULL)
summaryRprof(pfile,memory="both") # show the memory consumption profile

然后评估内存消耗情况......

由于您的代码因“内存不足”异常而停止,您应该将输入数据减少到使代码可用的数量,并使用此输入进行内存分析...

答案 1 :(得分:0)

您可以尝试使用ff包。它适用于磁盘数据。