use_java {rJavaEnv} | R Documentation |
JAVA_HOME
and PATH
environment variables in current R sessionUsing specified Java version, set the JAVA_HOME
and PATH
environment variables in the current R session. If Java distribtuion has not been downloaded yet, download it. If it was not installed into cache directory yet, install it there and then set the environment variables. This is intended as a quick and easy way to use different Java versions in R scripts that are in the same project, but require different Java versions. For example, one could use this in scripts that are called by targets
package or callr
package.
use_java(
version = NULL,
distribution = "Corretto",
cache_path = getOption("rJavaEnv.cache_path"),
platform = platform_detect()$os,
arch = platform_detect()$arch,
quiet = TRUE
)
version |
|
distribution |
The Java distribution to download. If not specified, defaults to "Amazon Corretto". Currently only "Amazon Corretto" is supported. |
cache_path |
The destination directory to download the Java distribution to. Defaults to a user-specific data directory. |
platform |
The platform for which to download the Java distribution. Defaults to the current platform. |
arch |
The architecture for which to download the Java distribution. Defaults to the current architecture. |
quiet |
A |
NULL
. Prints the message that Java was set in the current R session if quiet
is set to FALSE
.
## Not run:
# set cache directory for Java to be in temporary directory
options(rJavaEnv.cache_path = tempdir())
# install and set Java 8 in current R session
use_java(8)
# check Java version
"8" == java_check_version_cmd(quiet = TRUE)
"8" == java_check_version_rjava(quiet = TRUE)
# install and set Java 17 in current R session
use_java(17)
# check Java version
"17" == java_check_version_cmd(quiet = TRUE)
"17" == java_check_version_rjava(quiet = TRUE)
## End(Not run)