Package 'rJavaEnv'

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

Help Index


Check installed Java version using terminal commands

Description

Check installed Java version using terminal commands

Usage

java_check_version_cmd(java_home = NULL)

Arguments

java_home

Path to Java home directory. If NULL, the function uses the JAVA_HOME environment variable.

Value

TRUE if successful, otherwise FALSE.

Examples

java_check_version_cmd()

Check Java Version with a Specified JAVA_HOME Using a Separate R Session

Description

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.

Usage

java_check_version_rjava(java_home = NULL, verbose = TRUE)

Arguments

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.

Value

TRUE if successful, otherwise FALSE.

Examples

java_check_version_rjava()

Manage Java installations and distributions caches

Description

Wrapper function to clear the Java symlinked in the current project, installed, or distributions caches.

Usage

java_clear(
  type = c("project", "installed", "distrib"),
  target_dir = NULL,
  check = TRUE,
  delete_all = FALSE
)

Arguments

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.

Value

A message indicating whether the cache was cleared or not.

Examples

java_clear("project")
java_clear("installed")
java_clear("distrib")

Clear the Java distributions cache folder

Description

Clear the Java distributions cache folder

Usage

java_clear_distrib_cache(
  check = TRUE,
  delete_all = FALSE,
  cache_dir = tools::R_user_dir("rJavaEnv", which = "cache")
)

Arguments

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.

Value

A message indicating whether the cache was cleared or not.

Examples

## Not run: 
java_clear_distrib_cache()

## End(Not run)

Clear the Java versions symlinked in the current project

Description

Clear the Java versions symlinked in the current project

Usage

java_clear_in_project(project_dir = getwd(), check = TRUE, delete_all = FALSE)

Arguments

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.

Value

A message indicating whether the symlinks were cleared or not.

Examples

## Not run: 
java_clear_in_project()

## End(Not run)

Clear the Java installations cache folder

Description

Clear the Java installations cache folder

Usage

java_clear_installed_cache(
  check = TRUE,
  delete_all = FALSE,
  cache_dir = tools::R_user_dir("rJavaEnv", which = "cache")
)

Arguments

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.

Value

A message indicating whether the cache was cleared or not.

Examples

## Not run: 
java_clear_installed_cache()

## End(Not run)

Download a Java distribution

Description

Download a Java distribution

Usage

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
)

Arguments

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.

Value

The path to the downloaded Java distribution file.

Examples

## 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

Description

Set the JAVA_HOME and PATH environment variables to a given path

Usage

java_env_set(java_home, where = c("both", "session", "project"), verbose = T)

Arguments

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.

Value

Nothing. Sets the JAVA_HOME and PATH environment variables.

Examples

## Not run: 
java_env_set("/path/to/java", "both")

## End(Not run)

Unset the JAVA_HOME and PATH environment variables in the project .Rprofile

Description

Unset the JAVA_HOME and PATH environment variables in the project .Rprofile

Usage

java_env_unset(verbose = TRUE)

Arguments

verbose

Whether to print detailed messages. Defaults to TRUE.

Value

Nothing. Removes the JAVA_HOME and PATH environment variables settings from the project .Rprofile.

Examples

## Not run: 
java_env_unset()

## End(Not run)

Install Java from a distribution file

Description

Install Java from a distribution file

Usage

java_install(
  java_path,
  project = NULL,
  autoset_java_path = TRUE,
  verbose = TRUE
)

Arguments

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.

Value

The path to the installed Java directory.

Examples

## Not run: 
java_install("path/to/any-java-17-aarch64-macos-jdk.tar.gz")

## End(Not run)

List the contents of the Java cache

Description

List the contents of the Java cache

Usage

java_list(
  type = c("project", "installed", "distrib"),
  output = c("data.frame", "vector"),
  verbose = FALSE,
  target_dir = NULL
)

Arguments

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".

Value

A data frame or character vector with the contents of the specified cache directory.

Examples

java_list("project")
java_list("installed")
java_list("distrib")

List the contents of the Java distributions cache folder

Description

List the contents of the Java distributions cache folder

Usage

java_list_distrib_cache(
  output = c("data.frame", "vector"),
  verbose = FALSE,
  cache_dir = tools::R_user_dir("rJavaEnv", which = "cache")
)

Arguments

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.

Value

A character vector with the contents of the cache directory.

Examples

java_list_distrib_cache()

List the Java versions symlinked in the current project

Description

List the Java versions symlinked in the current project

Usage

java_list_in_project(
  project_dir = getwd(),
  output = c("data.frame", "vector"),
  verbose = FALSE
)

Arguments

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.

Value

A data frame or character vector with the symlinked Java versions in the project directory.

Examples

java_list_in_project()

List the contents of the Java installations cache folder

Description

List the contents of the Java installations cache folder

Usage

java_list_installed_cache(
  output = c("data.frame", "vector"),
  verbose = FALSE,
  cache_dir = tools::R_user_dir("rJavaEnv", which = "cache")
)

Arguments

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.

Value

A data frame or character vector with the contents of the cache directory.

Examples

java_list_installed_cache()

Download and install and set Java in current working/project directory

Description

Download and install and set Java in current working/project directory

Usage

java_quick_install(
  version = 21,
  distribution = "Corretto",
  platform = platform_detect()$os,
  arch = platform_detect()$arch,
  verbose = TRUE
)

Arguments

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.

Value

Message indicating that Java was installed and set in the current working/project directory.

Examples

## Not run: 
java_quick_install()

## End(Not run)