我有以下代码用于在我的.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的内存限制......
答案 0 :(得分:2)
是的,R启动时有2GB的限制,至少在执行用户配置文件(.Rprofile文件和.First()函数)时。
证明:
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
memory.limit
的输出> memory.limit()
[1] 16289