Title: | Java Environments for R Projects |
---|---|
Description: | Install specific version of Java runtime environment at the R project level. The goal of rJavaEnv is to manage multiple Java JDKs in R projects by automatingthe process of downloading, installing, and configuring Java environments on a per-project basis. This package is inspired by the renv <https://rstudio.github.io/renv/> package for managing R environments in R projects. You can request a specific Java Development Kit (JDK) in your project, and rJavaEnv will download and install the requested Java environment in a project-specific directory and set the PATH and JAVA_HOME for when you are using this project. Therefore, you can have different Java versions for different projects without contaminating your system with different Java versions. |
Authors: | Egor Kotov [aut, cre, cph] |
Maintainer: | Egor Kotov <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.1 |
Built: | 2024-09-28 05:57:59 UTC |
Source: | https://github.com/e-kotov/rJavaEnv |
Check installed Java version using terminal commands
java_check_version_cmd(java_home = NULL)
java_check_version_cmd(java_home = NULL)
java_home |
Path to Java home directory. If NULL, the function uses the JAVA_HOME environment variable. |
TRUE if successful, otherwise FALSE.
java_check_version_cmd()
java_check_version_cmd()
This function sets the JAVA_HOME environment variable, initializes the JVM using rJava, and prints the Java version that would be used if the user sets the given JAVA_HOME in the current R session. This check is performed in a separate R session to avoid having to reload the current R session. The reason for this is that once Java is initialized in an R session, it cannot be uninitialized unless the current R session is restarted.
java_check_version_rjava(java_home = NULL, verbose = TRUE)
java_check_version_rjava(java_home = NULL, verbose = TRUE)
java_home |
The path to the desired JAVA_HOME. If NULL, uses the current JAVA_HOME environment variable. |
verbose |
Whether to print detailed messages. Defaults to TRUE. |
TRUE if successful, otherwise FALSE.
java_check_version_rjava()
java_check_version_rjava()
Wrapper function to clear the Java symlinked in the current project, installed, or distributions caches.
java_clear( type = c("project", "installed", "distrib"), target_dir = NULL, check = TRUE, delete_all = FALSE )
java_clear( type = c("project", "installed", "distrib"), target_dir = NULL, check = TRUE, delete_all = FALSE )
type |
What to clear: "project" - remove symlinks to install cache in the current project, "installed" - remove installed Java versions, "distrib" - remove downloaded Java distributions. |
target_dir |
The directory to clear. Defaults to current working directory for "project" and user-specific data directory for "installed" and "distrib". Not recommended to change. |
check |
Whether to list the contents of the cache directory before clearing it. Defaults to TRUE. |
delete_all |
Whether to delete all items without prompting. Defaults to FALSE. |
A message indicating whether the cache was cleared or not.
java_clear("project") java_clear("installed") java_clear("distrib")
java_clear("project") java_clear("installed") java_clear("distrib")
Clear the Java distributions cache folder
java_clear_distrib_cache( check = TRUE, delete_all = FALSE, cache_dir = tools::R_user_dir("rJavaEnv", which = "cache") )
java_clear_distrib_cache( check = TRUE, delete_all = FALSE, cache_dir = tools::R_user_dir("rJavaEnv", which = "cache") )
check |
Whether to list the contents of the cache directory before clearing it. Defaults to TRUE. |
delete_all |
Whether to delete all distributions without prompting. Defaults to FALSE. |
cache_dir |
The cache directory to clear. Defaults to the user-specific data directory. |
A message indicating whether the cache was cleared or not.
## Not run: java_clear_distrib_cache() ## End(Not run)
## Not run: java_clear_distrib_cache() ## End(Not run)
Clear the Java versions symlinked in the current project
java_clear_in_project(project_dir = getwd(), check = TRUE, delete_all = FALSE)
java_clear_in_project(project_dir = getwd(), check = TRUE, delete_all = FALSE)
project_dir |
The project directory to clear. Defaults to the current working directory. |
check |
Whether to list the symlinked Java versions before clearing them. Defaults to TRUE. |
delete_all |
Whether to delete all symlinks without prompting. Defaults to FALSE. |
A message indicating whether the symlinks were cleared or not.
## Not run: java_clear_in_project() ## End(Not run)
## Not run: java_clear_in_project() ## End(Not run)
Clear the Java installations cache folder
java_clear_installed_cache( check = TRUE, delete_all = FALSE, cache_dir = tools::R_user_dir("rJavaEnv", which = "cache") )
java_clear_installed_cache( check = TRUE, delete_all = FALSE, cache_dir = tools::R_user_dir("rJavaEnv", which = "cache") )
check |
Whether to list the contents of the cache directory before clearing it. Defaults to TRUE. |
delete_all |
Whether to delete all installations without prompting. Defaults to FALSE. |
cache_dir |
The cache directory to clear. Defaults to the user-specific data directory. |
A message indicating whether the cache was cleared or not.
## Not run: java_clear_installed_cache() ## End(Not run)
## Not run: java_clear_installed_cache() ## End(Not run)
Download a Java distribution
java_download( version = 21, distribution = "Corretto", dest_dir = tools::R_user_dir("rJavaEnv", which = "cache"), platform = platform_detect()$os, arch = platform_detect()$arch, verbose = TRUE )
java_download( version = 21, distribution = "Corretto", dest_dir = tools::R_user_dir("rJavaEnv", which = "cache"), platform = platform_detect()$os, arch = platform_detect()$arch, verbose = TRUE )
version |
The Java version to download. If not specified, defaults to the latest LTS version. |
distribution |
The Java distribution to download. If not specified, defaults to "Corretto". |
dest_dir |
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. |
verbose |
Whether to print detailed messages. Defaults to TRUE. |
The path to the downloaded Java distribution file.
## Not run: java_download(version = "17", distribution = "Corretto") java_download(distribution = "Corretto") java_download() ## End(Not run)
## Not run: java_download(version = "17", distribution = "Corretto") java_download(distribution = "Corretto") java_download() ## End(Not run)
Set the JAVA_HOME and PATH environment variables to a given path
java_env_set(java_home, where = c("both", "session", "project"), verbose = T)
java_env_set(java_home, where = c("both", "session", "project"), verbose = T)
java_home |
The path to the desired JAVA_HOME. |
where |
Where to set the JAVA_HOME: "session", "project", or "both". Defaults to "both". When "both" or "project" is selected, the function updates the .Rprofile file in the project directory to set the JAVA_HOME and PATH environment variables at the start of the R session. |
verbose |
Whether to print detailed messages. Defaults to TRUE. |
Nothing. Sets the JAVA_HOME and PATH environment variables.
## Not run: java_env_set("/path/to/java", "both") ## End(Not run)
## Not run: java_env_set("/path/to/java", "both") ## End(Not run)
Unset the JAVA_HOME and PATH environment variables in the project .Rprofile
java_env_unset(verbose = TRUE)
java_env_unset(verbose = TRUE)
verbose |
Whether to print detailed messages. Defaults to TRUE. |
Nothing. Removes the JAVA_HOME and PATH environment variables settings from the project .Rprofile.
## Not run: java_env_unset() ## End(Not run)
## Not run: java_env_unset() ## End(Not run)
Install Java from a distribution file
java_install( java_path, project = NULL, autoset_java_path = TRUE, verbose = TRUE )
java_install( java_path, project = NULL, autoset_java_path = TRUE, verbose = TRUE )
java_path |
The path to the Java distribution file. |
project |
The project directory where Java should be installed. Defaults to the current working directory. |
autoset_java_path |
Whether to set the JAVA_HOME and PATH environment variables to the installed Java directory. Defaults to TRUE. |
verbose |
Whether to print detailed messages. Defaults to TRUE. |
The path to the installed Java directory.
## Not run: java_install("path/to/any-java-17-aarch64-macos-jdk.tar.gz") ## End(Not run)
## Not run: java_install("path/to/any-java-17-aarch64-macos-jdk.tar.gz") ## End(Not run)
List the contents of the Java cache
java_list( type = c("project", "installed", "distrib"), output = c("data.frame", "vector"), verbose = FALSE, target_dir = NULL )
java_list( type = c("project", "installed", "distrib"), output = c("data.frame", "vector"), verbose = FALSE, target_dir = NULL )
type |
The type of cache to list: "distrib", "installed", or "project". |
output |
The format of the output: "data.frame" or "vector". Defaults to "data.frame". |
verbose |
Whether to print detailed messages. Defaults to FALSE. |
target_dir |
The cache directory to list. Defaults to the user-specific data directory for "distrib" and "installed", and the current working directory for "project". |
A data frame or character vector with the contents of the specified cache directory.
java_list("project") java_list("installed") java_list("distrib")
java_list("project") java_list("installed") java_list("distrib")
List the contents of the Java distributions cache folder
java_list_distrib_cache( output = c("data.frame", "vector"), verbose = FALSE, cache_dir = tools::R_user_dir("rJavaEnv", which = "cache") )
java_list_distrib_cache( output = c("data.frame", "vector"), verbose = FALSE, cache_dir = tools::R_user_dir("rJavaEnv", which = "cache") )
output |
The format of the output: "data.frame" or "vector". Defaults to "data.frame". |
verbose |
Whether to print detailed messages. Defaults to FALSE. |
cache_dir |
The cache directory to list. Defaults to the user-specific data directory. |
A character vector with the contents of the cache directory.
java_list_distrib_cache()
java_list_distrib_cache()
List the Java versions symlinked in the current project
java_list_in_project( project_dir = getwd(), output = c("data.frame", "vector"), verbose = FALSE )
java_list_in_project( project_dir = getwd(), output = c("data.frame", "vector"), verbose = FALSE )
project_dir |
The project directory to list. Defaults to the current working directory. |
output |
The format of the output: "data.frame" or "vector". Defaults to "data.frame". |
verbose |
Whether to print detailed messages. Defaults to FALSE. |
A data frame or character vector with the symlinked Java versions in the project directory.
java_list_in_project()
java_list_in_project()
List the contents of the Java installations cache folder
java_list_installed_cache( output = c("data.frame", "vector"), verbose = FALSE, cache_dir = tools::R_user_dir("rJavaEnv", which = "cache") )
java_list_installed_cache( output = c("data.frame", "vector"), verbose = FALSE, cache_dir = tools::R_user_dir("rJavaEnv", which = "cache") )
output |
The format of the output: "data.frame" or "vector". Defaults to "data.frame". |
verbose |
Whether to print detailed messages. Defaults to FALSE. |
cache_dir |
The cache directory to list. Defaults to the user-specific data directory. Not recommended to change. |
A data frame or character vector with the contents of the cache directory.
java_list_installed_cache()
java_list_installed_cache()
Download and install and set Java in current working/project directory
java_quick_install( version = 21, distribution = "Corretto", platform = platform_detect()$os, arch = platform_detect()$arch, verbose = TRUE )
java_quick_install( version = 21, distribution = "Corretto", platform = platform_detect()$os, arch = platform_detect()$arch, verbose = TRUE )
version |
The Java version to download. If not specified, defaults to the latest LTS version. |
distribution |
The Java distribution to download. If not specified, defaults to "Corretto". |
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. |
verbose |
Whether to print messages. Defaults to TRUE. |
Message indicating that Java was installed and set in the current working/project directory.
## Not run: java_quick_install() ## End(Not run)
## Not run: java_quick_install() ## End(Not run)