【问题标题】:Is there a 2GB memory usage limit when R boots?R启动时是否有2GB内存使用限制?
【发布时间】:2015-12-11 10:36:09
【问题描述】:

我有以下代码用于在我的 .Rprofile 中加载一些数据(这是我的项目文件夹中的一个 R 脚本,当我使用 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")
}

加载的数据比较大:

                             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 内存限制...

【问题讨论】:

  • 系统通常不允许单个程序或进程分配所有内存。由于答案是系统特定的,请添加您正在使用的操作系统
  • @RHertel:似乎与我无关,我确实有足够的内存(12-14 GB 可用...)。
  • 我认为这仍然有些相关。您可以使用memory.limit() 查看可以分配的最大内存。您也可以使用相同的函数来增加最大值。
  • @SamDickson 正如您在我的帖子中看到的那样,我知道该功能,它确实表明 16GB 可用。我的系统监视器显示我正在使用 16GB 中的 4GB,因此可用内存不是问题。此外,一旦 R 启动,我就可以加载数据。我的问题是,当加载代码写入 .Rprofile 文件时,为什么加载代码似乎达到了 2GB 内存限制。

标签: r memory memory-management


【解决方案1】:

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

证明:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-08
    • 2017-11-02
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多