Search code examples
javarrjavar-xlsx

How to deal with "Java Heap Space" error while running rjava


I am using rJava package in R on MacOS. This error happened:

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

I need rJava to open an Excel file with xlsx package. With this error I can not read the .xlsx files. I wonder how to solve this problem?


Solution

  • You need to modify the java parameters with the following function at the start of your script.

    options(java.parameters = "-Xmx8000m")
    

    You may also need restart your environment first.