如何检查R中的RAM量 [英] How to check the amount of RAM in R
问题描述
我想制作一个函数,根据某人系统上可用的 RAM 大小,以不同数量的批次导入数据.但是如何在 R 中找到可用 RAM 的数量?我可以使用 memory.size()
但这只适用于 Windows.
I want to make a function that imports data in different numbers of batches depending on how much RAM is available on someones system. But how can I find the amount of available RAM in R? I can use memory.size()
but that only works for Windows.
推荐答案
鉴于前面评论中讨论的有关平台依赖性的警告,您可以例如在 Linux 上解析 /proc/meminfo
:
Given the warnings concerning platform-dependency discussed in the earlier comment, you could for example parse /proc/meminfo
on Linux:
$ grep MemFree /proc/meminfo
MemFree: 573660 kB
$ awk '/MemFree/ {print $2}' /proc/meminfo
565464
您可以通过 system(..., intern=TRUE)
甚至通过管道连接尝试第二种方法.
You could try the second approach via system(..., intern=TRUE)
, or even via a pipe connection.
大约 5 年后 在 R 中,并遵循上一段暗示的内容:
Edit some 5+ years later: In R, and just following what the previous paragraph hinted at:
R> memfree <- as.numeric(system("awk '/MemFree/ {print $2}' /proc/meminfo",
+ intern=TRUE))
R> memfree
[1] 3342480
R>
这篇关于如何检查R中的RAM量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!