Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(java_clear)
export(java_download)
export(java_env_set)
export(java_env_unset)
export(java_get_home)
export(java_install)
export(java_list)
export(java_quick_install)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- New function `java_build_env_set()` that sets the environment (either temporarily in the current session or in `./.Rprofile` file of the current working directory) to build `rJava` from source on `macOS`, `Linux` and `Windows` platforms. It uses the current value of `JAVA_HOME` environment variable by default, so that it is more convenient to use after `java_quick_install()` or `use_java()` commands. After running `java_build_env_set()`, users can install `rJava` from source with `install.packages("rJava", type = "source")` without any additional configuration. However, users will still need some system dependencies, e.g. on Linux they will need: libpcre2-dev, libdeflate-dev, libzstd-dev, liblzma-dev, libbz2-dev, zlib1g-dev, libicu-dev. A system message with a suggested `apt-get` command is printed. On Windows, `Rtools` must be installed. On `macOS`, `Xcode Command Line Tools` must be installed. See the new vignette `Install 'rJava' from source` for more details.

- New function `java_get_home()` to get currently set `JAVA_HOME`. This is just a shortcut to `Sys.getenv("JAVA_HOME")`, as it is faster to type and can be even faster then used with autocomplete.

## Improvements

- `java_quick_install()` now also invisibly returns the path to `JAVA_HOME`.
Expand Down
14 changes: 14 additions & 0 deletions R/java_env.R
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,17 @@ java_env_unset <- function(
}
}
}

#' @title Get JAVA_HOME
#' @description Get the current JAVA_HOME environment variable.
#' @return The value of the JAVA_HOME environment variable.
#' @export
#' @examples
#' java_get_home()
java_get_home <- function() {
java_home <- Sys.getenv("JAVA_HOME", unset = NA)
if (is.na(java_home) || java_home == "") {
return("")
}
java_home
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ reference:
contents:
- java_check_version_cmd
- java_check_version_rjava
- java_get_home
- title: "Fine-grained Control"
desc: >
Control every step of `Java` download, unpacking and installation
Expand Down
17 changes: 17 additions & 0 deletions man/java_get_home.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/testthat/test-java_env.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test_that("java_get_home() gets JAVA_HOME", {
withr::with_envvar(
c("JAVA_HOME" = "/path/to/java"),
expect_equal(java_get_home(), "/path/to/java")
)
})

test_that("java_get_home() returns empty string when JAVA_HOME is not set", {
withr::with_envvar(
c("JAVA_HOME" = NA),
{
Sys.unsetenv("JAVA_HOME")
expect_equal(java_get_home(), "")
}
)
})
Loading