
Execute rJava code in a separate process with specific Java version
Source:R/java_scoped.R
with_rjava_env.RdRuns the provided function in a fresh R subprocess where rJava has not yet
been loaded. This allows you to enforce a specific Java version for rJava
operations without affecting the main R session or requiring a restart.
Arguments
- version
Integer or character. Required. The Java version you need (e.g., 17, 21). Defaults to
NULL, which is invalid and will trigger a validation error; callers should always provide a non-NULLvalue explicitly.- func
The function to execute in the subprocess.
- args
A list of arguments to pass to
func.- distribution
Character. The Java distribution to download. Defaults to "Corretto".
- install
Logical. If
TRUE(default), attempts to download/install if missing. IfFALSE, returnsFALSEif the version is not found.- accept_system_java
Logical. If
TRUE(default), the function will scan the system for existing Java installations (usingJAVA_HOME,PATH, and OS-specific locations). If a system Java matching theversionandtyperequirements is found, it will be used. Set toFALSEto ignore system installations and strictly use anrJavaEnvmanaged version.- quiet
A
logicalvalue indicating whether to suppress messages. Can beTRUEorFALSE.- libpath
Optional character vector of library paths to use in the subprocess. Defaults to
.libPaths().