“内存不足错误(Java)”使用 R 和 XLConnect 包时

发布于 2024-12-12 21:22:01 字数 319 浏览 0 评论 0原文

我尝试使用 XLConnect 包将约 30MB 的 Excel 电子表格加载到 R 中。

这就是我写的:

wb <- loadWorkbook("largespreadsheet.xlsx")

大约 15 秒后,我收到以下错误:

错误:OutOfMemoryError (Java):超出 GC 开销限制。

这是 XLConnect 软件包的限制还是有办法调整我的内存设置以允许更大的文件?

我很感激任何解决方案/提示/建议。

I tried to load a ~30MB excel spreadsheet into R using the XLConnect package.

This is what I wrote:

wb <- loadWorkbook("largespreadsheet.xlsx")

And after about 15 seconds, I got the following error:

Error: OutOfMemoryError (Java): GC overhead limit exceeded.

Is this a limitation of the XLConnect package or is there a way to tweak my memory settings to allow for larger files?

I appreciate any solutions/tips/advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

韶华倾负 2024-12-19 21:22:01

请遵循其网站的建议:

options(java.parameters = "-Xmx1024m")
library(XLConnect)

Follow the advice from their website:

options(java.parameters = "-Xmx1024m")
library(XLConnect)
笔落惊风雨 2024-12-19 21:22:01

如果您在导入 XLSX 文件时仍然遇到问题,可以使用此选项。带有“Xmx1024m”的 Anwser 不起作用,我改为“-Xmx4g”。

options(java.parameters = "-Xmx4g" )
library(XLConnect)

链接很有用。

If you still have problems with importing XLSX files you can use this opiton. Anwser with "Xmx1024m" didn't work and i changed to "-Xmx4g".

options(java.parameters = "-Xmx4g" )
library(XLConnect)

This link was useful.

長街聽風 2024-12-19 21:22:01

万一有人在读取不是一个大文件而是许多个文件时遇到此错误,我设法通过使用 xlcFreeMemory() 释放 Java 虚拟机内存来解决此错误,因此:

files <- list.files(path, pattern = "*.xlsx")
for (i in seq_along(files)) {
    wb <- loadWorkbook(...)
    ...
    rm(wb)
    xlcFreeMemory()  # <= free Java Virtual Machine memory !
}

In case someone encounters this error when reading not one huge but many files, I managed to solve this error by freeing Java Virtual Machine memory with xlcFreeMemory(), thus:

files <- list.files(path, pattern = "*.xlsx")
for (i in seq_along(files)) {
    wb <- loadWorkbook(...)
    ...
    rm(wb)
    xlcFreeMemory()  # <= free Java Virtual Machine memory !
}
沉睡月亮 2024-12-19 21:22:01

openxlsx 中使用 read.xlsx() > 包。它不依赖于 rJava,因此仅具有 R 本身的内存限制。我还没有深入探索如何编写和格式化 XLSX,但它有一些看起来很有前途的小插曲。对于阅读大型电子表格,它效果很好。

向@Brad-Horn 致敬。我刚刚将他的评论作为答案,因为我也发现这是最好的解决方案!

Use read.xlsx() in the openxlsx package. It has no dependency on rJava thus only has the memory limitations of R itself. I have not explored in much depth for writing and formatting XLSX but it has some promising looking vignettes. For reading large spreadsheets, it works well.

Hat tip to @Brad-Horn. I've just turned his comment as an answer because I also found this to be the best solution!

屋檐 2024-12-19 21:22:01

每当您使用依赖于 rJava 的库(例如我的例子中的 RWeka)时,总有一天您会遇到默认堆空间(512 MB)。现在,当您使用 Java 时,我们都知道要使用的 JVM 参数(如果您需要 2 GB RAM,则为 -Xmx2048m)。这里只是如何在 R 环境中指定它的问题。

   options(java.parameters = "-Xmx2048m")
   library(rJava)

Whenever you are using a library that relies on rJava (such as RWeka in my case), you are bound to hit the default heap space (512 MB) some day. Now, when you are using Java, we all know the JVM argument to use (-Xmx2048m if you want 2 gigabytes of RAM). Here it's just a matter of how to specify it in the R environnement.

   options(java.parameters = "-Xmx2048m")
   library(rJava)
多情癖 2024-12-19 21:22:01

As suggested in this here, make sure to run the option function in the first line in your code. In my case, it worked only when I restarted the R session and run it in the first line.

options(java.parameters = "-Xmx4g" )
library(XLConnect)
dawn曙光 2024-12-19 21:22:01

当您一遍又一遍地使用相同的 R 会话而不重新启动 R-Studio 时,情况似乎就是这样。重新启动 R-Studio 有助于为程序分配新的内存堆。它立即对我有用。

This appears to be the case, when u keep using the same R-session over and over again without restarting R-Studio. Restarting R-Studio can help to allocate a fresh memory-heap to the program. It worked for me right away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文