0

I was trying to install and run a R Code, the .xlsx package install successfully, but when I am trying to source it, this is the error that is returned:

Error: package or namespace load failed for ‘xlsx’: .onLoad failed in loadNamespace() for 'xlsx', details: call: .jinit() error: Cannot create Java virtual machine (-6)

I went through topics on here where a new environment variable could be created, but that didn't help either. I went onto 2048M for the variable, but it still did not work.

Does anyone have any insights as to what else might be causing this?

smci
  • 32,567
  • 20
  • 113
  • 146
Vijul
  • 1
  • 2
  • You could try the `readxl` package, that package does not depend on Java. – Dave2e Aug 16 '18 at 19:45
  • 2
    You are running rJava, and the error seems related to the JVM, not your packages. Try to run plain old R, and debug your issue from there. Related: [R - Error : .onLoad failed in loadNamespace() for 'rJava'](https://stackoverflow.com/questions/37735108/r-error-onload-failed-in-loadnamespace-for-rjava) – smci Aug 16 '18 at 19:48

1 Answers1

0

Had exactly the same Cannot create Java virtual machine (-6) error in RStudio. Then thanks to @smci started to debug using plain R.

I have set the following System environment variables:

JAVA_HOME = C:\Program Files (x86)\Java\jre1.8.0_192
_JAVA_OPTIONS = -Xmx512M

Using 32-bit for R and Java, and then increasing heap size into -Xmx2048M, Java seem not work in R:

C:\Program Files\R\R-3.5.1\bin\i386>R.exe

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(rJava)
> .jinit()
Picked up _JAVA_OPTIONS: -Xmx2048M
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap

Then after reducing the heap size back to -Xmx512M everything went fine:

C:\Program Files\R\R-3.5.1\bin\i386>R.exe

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(rJava)
> .jinit()
Picked up _JAVA_OPTIONS: -Xmx512M

In RStudio, I had to also disable setting similar option as it would cause the conflict:

# Try to use a bit more memory (works only in 64-bit Java)
#options(java.parameters = "-Xmx8000m")

After that I got rid of the error message.

Heikki
  • 2,214
  • 19
  • 34