简体   繁体   English

R启动时如何覆盖2GB内存限制

[英]how to override the 2GB memory limit when R starts

When R boots, the memory limit (as returned by memory.limit) is set to 2GB, regardless of the available memory on the computer. 当R启动时,无论计算机上的可用内存如何,内存限制(由mem​​ory.limit返回)都设置为2GB。 ( I found that out recently ). 我最近发现了 )。 I imagine that at some point in the booting process, this limit is set to the actually available memory. 我想在启动过程中的某个时刻,此限制被设置为实际可用的内存。

This can be seen by printing memory.limit() in the .Rprofile file which is sourced at startup. 这可以通过在启动时获取的.Rprofile文件中打印memory.limit()来看出。 It prints "2047". 它打印“2047”。 On the other hand, when R has booted and I type memory.limit() in the console, I get "16289". 另一方面,当R启动并在控制台中键入memory.limit()时,我得到“16289”。

I use a custom .Rprofile file and I need to have access to more than 2GB during bootup. 我使用自定义.Rprofile文件,我需要在启动时访问超过2GB。

How can override this limit? 如何覆盖此限制?

My current workaround is to set the limit myself in the .Rprofile using memory.limit(size=16289) but then I will have to edit this every time I work on a computer with a different amount of RAM which happens fairly often. 我目前的解决方法是使用memory.limit(size=16289)在.Rprofile中设置限制,但是每次我在具有不同RAM量的计算机上工作时我都必须编辑这个。

Is there an option I can change, a .ini file I can edit, or anything I can do about it? 有没有我可以更改的选项,我可以编辑的.ini文件,或者我可以做些什么呢?

OS and R version: OS和R版本:

> 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

Edit: this is not a duplicate , at least not a duplicate of the proposed question. 编辑:这不是重复 ,至少不是建议问题的重复。 It is not about managing available memory! 它不是关于管理可用内存! I have 16GB of memory and memory.limit() shows that my limit is indeed 16GB. 我有16GB的内存和memory.limit()表明我的限制确实是16GB。

It all started when I got the warning that I had "reached 2GB memory allocation" (implicating that I had a 2GB memory limit). 这一切都始于我收到“已达到2GB内存分配”的警告(暗示我有2GB的内存限制)。 After investigation, it appears that indeed R limits the memory at 2GB during the startup process . 经过调查,看来R确实在启动过程中将内存限制在2GB

I want to load my data automatically when R starts, for this I have a small loading script in the .Rprofile . 我想在R启动时自动加载我的数据,为此我在.Rprofile中有一个小的加载脚本。 I load more than 2GB data hence I need to have access to my 16GB. 我加载超过2GB的数据因此我需要访问我的16GB。 My question is about achieving this. 我的问题是关于实现这一点。 This has nothing at all in common with the proposed duplicate, except keywords... 除了关键字之外,这与提议的副本没有任何共同之处 ......

I'm interpreting this as you wanting memory.limit(size=16289) in your .RProfile file, but you don't want to set the specific number every time you change computers with different memory. 我在你的.RProfile文件中想要memory.limit(size=16289) ,但是你不想在每次更换具有不同内存的计算机时设置特定的数字。 Why not just dynamically pull the memory you need? 为什么不动态拉动你需要的内存? In windows: 在Windows中:

TOT_MEM <- as.numeric(gsub("\r","",gsub("TotalVisibleMemorySize=","",system('wmic OS get TotalVisibleMemorySize /Value',intern=TRUE)[3])))/1024
memory.limit(size=TOT_MEM)

which would set the available memory to the total memory of the system, or 这会将可用内存设置为系统的总内存,或者

FREE_MEM <- as.numeric(gsub("\r","",gsub("FreePhysicalMemory=","",system('wmic OS get FreePhysicalMemory /Value',intern=TRUE)[3])))/1024
memory.limit(size=FREE_MEM)

which would set memory.limit to the total available memory on boot. 这会将memory.limit设置为启动时的总可用内存。

Place this in RProfile, above where you load your data. 将其放在RProfile中,位于加载数据的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM