0

First of all I must say that I have long looked for a solution to my problem and that starting this thread is a desperate attempt. All the information (and their respective solutions) relate to memory leaks when running several iterations of a code or when dealing with heavy files (>500Mb). But that's not my case.

My code -before the error is triggered- looks like this:

library(tidyverse)
library(lubridate)
library(XLConnect)
library(tibble)
library(rJava)

path <- "file_path/file_name.xlsx"

wb <- loadWorkbook(path)

This triggers the following message:

Error: OutOfMemoryError (Java): Java heap space

The size of file is only 7Mb. If I try uploading a smaller file (500Kb) I get no error. I already tried setting a higher value for Java memory with options(java.parameters = "-Xmx8g") but it didn't solve the problem.

Garbage Collector looks like this:

      used (Mb) gc trigger  (Mb) max used  (Mb)

Ncells 1157125 61.8 2240345 119.7 2240345 119.7

Vcells 1793273 13.7 8388608 64.0 2904659 22.2

Does anyone have an idea of what could be causing this? My enviroment is completelly clean and I continously re-start my Rstudio session. The file is simply an .xlsx document that I need to load in order to fill columns with data from a dataframe.

2
  • Not a reply, but the readxl package might be an alternative, plus it's Java-free. There's also openxlsx if you need to do more than reading files. Commented Dec 14, 2023 at 16:21
  • I normally use openxlsx, but for this project I encountered an issue that could not be overcome, and so I need to use XLConnect (or, alternatively, xlsx; both Java-based). See: stackoverflow.com/questions/77556047/… Commented Dec 15, 2023 at 9:01

1 Answer 1

0

It is important to set Java options before the JVM is initialized and as such before any Java-related package is loaded. So you should have:

options(java.parameters = "-Xmx8g")

library(XLConnect)
path <- "file_path/file_name.xlsx"
wb <- loadWorkbook(path)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Martin, that's a good point. I was updating JVM memory from the console and somehow didn't realize about this. Now I'm getting an ERROR StatusLogger Log4j2 could not find a logging implementation error, but that's another story. I'd say your answer solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.