“内存不足错误(Java)”使用 R 和 XLConnect 包时
我尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
请遵循其网站的建议:
Follow the advice from their website:
如果您在导入 XLSX 文件时仍然遇到问题,可以使用此选项。带有“Xmx1024m”的 Anwser 不起作用,我改为“-Xmx4g”。
此链接很有用。
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".
This link was useful.
万一有人在读取不是一个大文件而是许多个文件时遇到此错误,我设法通过使用
xlcFreeMemory()
释放 Java 虚拟机内存来解决此错误,因此: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:在
openxlsx
中使用read.xlsx()
> 包。它不依赖于 rJava,因此仅具有 R 本身的内存限制。我还没有深入探索如何编写和格式化 XLSX,但它有一些看起来很有前途的小插曲。对于阅读大型电子表格,它效果很好。向@Brad-Horn 致敬。我刚刚将他的评论作为答案,因为我也发现这是最好的解决方案!
Use
read.xlsx()
in theopenxlsx
package. It has no dependency onrJava
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!
每当您使用依赖于 rJava 的库(例如我的例子中的 RWeka)时,总有一天您会遇到默认堆空间(512 MB)。现在,当您使用 Java 时,我们都知道要使用的 JVM 参数(如果您需要 2 GB RAM,则为 -Xmx2048m)。这里只是如何在 R 环境中指定它的问题。
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.
正如此处,确保运行代码第一行中的选项函数。就我而言,只有当我重新启动 R 会话并在第一行运行它时,它才起作用。
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.
当您一遍又一遍地使用相同的 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.