R data.table大小和内存限制

Kri*_*nan 7 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" 
Run Code Online (Sandbox Code Playgroud)

我得到以下内存分配错误(见图)

在此输入图像描述

我设置内存限制如下:

#memory.limit(size=7000000)
#Change memory.limit to 40GB when using ff library
memory.limit(size=40000)
Run Code Online (Sandbox Code Playgroud)

我的问题如下:

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

R Y*_*oda 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
Run Code Online (Sandbox Code Playgroud)

然后评估内存消耗配置文件......

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