R引导时是否有2GB的内存使用限制? [英] Is there a 2GB memory usage limit when R boots?

查看:86
本文介绍了R引导时是否有2GB的内存使用限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在.Rprofile中加载一些数据(当我使用Rstudio切换到项目时,这是我的项目文件夹中的R脚本会自动运行).

data_files <- list.files(pattern="\\.(RData|rda)$")
if("data.rda" %in% data_files) {
  attach(what="data.rda", 
         pos = 2)
  cat("The file 'data.rda' was attached to the search path under 'file:data.rda'.\n\n")
}

正在加载的数据相对较大:

                             Type       Size     PrettySize    Rows Columns
individual_viewings_26 data.frame 1547911120   [1] "1.4 Gb" 3685312      63
viewing_statements_all data.table  892316088   [1] "851 Mb" 3431935      38
weights                data.frame  373135464 [1] "355.8 Mb" 3331538      14
pet                    data.table   63926168    [1] "61 Mb"  227384      34

但是我有16 GB,我可以分配它们:

> memory.limit()
[1] 16289

当我的数据不那么大时,我没有任何问题.我最近在data.rda中保存了更多数据帧,并且我的R会话在启动时突然失败(当我切换到Rstudio中的项目并执行.Rprofile时):

Error: cannot allocate vector of size 26.2 Mb
In addition: Warning messages:
1: Reached total allocation of 2047Mb: see help(memory.size) 
2: Reached total allocation of 2047Mb: see help(memory.size) 
3: Reached total allocation of 2047Mb: see help(memory.size) 
4: Reached total allocation of 2047Mb: see help(memory.size) 

我怀疑出于某种原因,启动时内存限制设置为2GB?有什么办法可以改变吗?

添加了操作系统和软件版本

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Edit2:澄清一下,我能够通过运行代码自己加载数据,我有足够的可用内存,并且R进程在日常工作中通常使用高达10GB的内存.问题是,当R启动并执行.Rprofile ...时,显然存在2GB的内存限制.

解决方案

是的,至少在执行用户配置文件(.Rprofile文件和.First()函数)时,R启动时有2GB的限制.

证明:

Rprofile的内容:

message("Available memory when .Rprofile is sourced: ", memory.limit())

.First <- function() {
  message("Available memory when .First() is called: ", memory.limit())
}

启动时输出

Available memory when .Rprofile is sourced: 2047
Available memory when .First() is called: 2047

R开始后

memory.limit的输出

> memory.limit()
[1] 16289

I have the following code for loading some data in my .Rprofile (which is a R script in my project folder running automatically when I switch to the project with Rstudio).

data_files <- list.files(pattern="\\.(RData|rda)$")
if("data.rda" %in% data_files) {
  attach(what="data.rda", 
         pos = 2)
  cat("The file 'data.rda' was attached to the search path under 'file:data.rda'.\n\n")
}

The data being loaded is relatively big:

                             Type       Size     PrettySize    Rows Columns
individual_viewings_26 data.frame 1547911120   [1] "1.4 Gb" 3685312      63
viewing_statements_all data.table  892316088   [1] "851 Mb" 3431935      38
weights                data.frame  373135464 [1] "355.8 Mb" 3331538      14
pet                    data.table   63926168    [1] "61 Mb"  227384      34

But I have 16 GB and I can allocate them:

> memory.limit()
[1] 16289

When my data was not as big, I did not have any issue. I recently saved some more data frames in data.rda and my R session suddenly fails at start-up (when I switch to the project in Rstudio and .Rprofile is executed):

Error: cannot allocate vector of size 26.2 Mb
In addition: Warning messages:
1: Reached total allocation of 2047Mb: see help(memory.size) 
2: Reached total allocation of 2047Mb: see help(memory.size) 
3: Reached total allocation of 2047Mb: see help(memory.size) 
4: Reached total allocation of 2047Mb: see help(memory.size) 

I suspect that for some reason, the memory limit is set at 2GB at boot? Any way I can change that?

Edit: Added OS and software version

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Edit2: Just to clarify, I am able to load the data myself by running the code, I have plenty of available memory and the R process commonly uses up to 10GB during my daily work. The problem is, there is a apparently a 2GB memory limit when R boots and executes the .Rprofile...

解决方案

Yes, there is a 2GB limit when R starts, at least when the user profile (.Rprofile files and .First() functions) are executed.

Proof:

Content of Rprofile:

message("Available memory when .Rprofile is sourced: ", memory.limit())

.First <- function() {
  message("Available memory when .First() is called: ", memory.limit())
}

Output at startup

Available memory when .Rprofile is sourced: 2047
Available memory when .First() is called: 2047

Output of memory.limit once R has started

> memory.limit()
[1] 16289

这篇关于R引导时是否有2GB的内存使用限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆