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.