2

I am facing an error in R while trying to use read.xlsx function from package xlsx. Error says "

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : java.lang.OutOfMemoryError: Java heap space

I have tried using openxlsx package and it works fine but I want to use xlsx package only. I have also tried setting java parameters to increase the heap space after unloading all the packages from R session but it doesn't work. I am using 32 bit R, 32 bit Java on a 64 bit system and have declared all possible paths in my environment variables.

Thanks a lot for the help!

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
  • It's because of this issue that I gave up on the `xlsx` package and have moved to `readxl`, which is [faster](http://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script/31734198#31734198). I spent over a year trying to fix this issue -- the closest I could get was to be sure I ran `gc()` after _every_ time I called `read.xlsx`. Quite annoying. – MichaelChirico Feb 25 '16 at 02:27

1 Answers1

0

I somehow had this problem in a not reproducible manner, partly solved it with -Xmx8g but run in to problems randomly.

I described an option with a different garbage collector here by using

options(java.parameters = c("-XX:+UseConcMarkSweepGC", "-Xmx8192m"))
library(xlsx)

at the beginning of the script and before any other package is loaded since other packages can load some java things by themselves and the options have to be set before any Java is loaded.

So far, the problem didn't occurred again.

Only sometimes in a long session it can still happen. But in this case a session restart normally solves the problem.

drmariod
  • 11,106
  • 16
  • 64
  • 110