Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version to install_cmdstan #308

Merged
merged 3 commits into from
Oct 7, 2020
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
33 changes: 27 additions & 6 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
#' installation.
#' @param timeout Timeout (in seconds) for the CmdStan build stage of the
#' installation process.
#' @param release_url Specifies the URL to a specific Cmdstan release to be
#' @param version Specifies the Cmdstan release version to be
#' installed. By default set to `NULL`, which downloads the latest stable
#' release from [GitHub](https://github.com/stan-dev/cmdstan/releases).
#' @param release_url Specifies the URL to a specific Cmdstan release to be
#' installed. By default set to `NULL`, which downloads the latest stable
#' release from [GitHub](https://github.com/stan-dev/cmdstan/releases). If
#' `version` and `release_url` are set, `version` is used.
#' @param cpp_options A list specifying any makefile flags/variables to be
#' written to the `make/local` file. For example, `list("CXX" = "clang++")`
#' will force the use of clang for compilation.
Expand All @@ -53,6 +57,7 @@ install_cmdstan <- function(dir = NULL,
quiet = FALSE,
overwrite = FALSE,
timeout = 1200,
version = NULL,
release_url = NULL,
cpp_options = list()) {
if (is.null(dir)) {
Expand All @@ -64,7 +69,12 @@ install_cmdstan <- function(dir = NULL,
dir <- repair_path(dir)
checkmate::assert_directory_exists(dir, access = "rwx")
}

if (!is.null(version)) {
if (!is.null(release_url)) {
warning("version and release_url are supplied to install_cmdstan()!\nrelease_url will be ignored.")
}
release_url <- paste0("https://github.com/stan-dev/cmdstan/releases/download/v",version, "/cmdstan-", version, ".tar.gz")
}
if (!is.null(release_url)) {
if (!endsWith(release_url, ".tar.gz")) {
stop(release_url, " is not a .tar.gz archive!",
Expand Down Expand Up @@ -94,7 +104,13 @@ install_cmdstan <- function(dir = NULL,
}
tar_downloaded <- download_with_retries(download_url, dest_file)
if (!tar_downloaded) {
stop("GitHub download of Cmdstan failed.", call. = FALSE)
if (!is.null(version)) {
stop("Download of Cmdstan failed. Please check if the supplied version number is valid.", call. = FALSE)
}
if (!is.null(release_url)) {
stop("Download of Cmdstan failed. Please check if the supplied release URL is valid.", call. = FALSE)
}
stop("Download of Cmdstan failed. Please try again.", call. = FALSE)
}
message("* Download complete")

Expand Down Expand Up @@ -268,9 +284,14 @@ download_with_retries <- function(download_url,
quiet = TRUE) {
download_rc <- 1
while (retries > 0 && download_rc != 0) {
download_rc <- utils::download.file(url = download_url,
destfile = destination_file,
quiet = quiet)
try(
suppressWarnings(
download_rc <- utils::download.file(url = download_url,
destfile = destination_file,
quiet = quiet)
),
silent = TRUE
)
if (download_rc != 0) {
Sys.sleep(pause_sec)
}
Expand Down
8 changes: 7 additions & 1 deletion man/install_cmdstan.Rd

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

44 changes: 43 additions & 1 deletion tests/testthat/test-install.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,47 @@ test_that("install_cmdstan() errors if it times out", {
)
})

test_that("install_cmdstan() errors if invalid version or URL", {
skip_if_offline()
expect_error(
install_cmdstan(version = "2.23.2"),
"Download of Cmdstan failed. Please check if the supplied version number is valid."
)
expect_error(
install_cmdstan(release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.23.2/cmdstan-2.23.2.tar.gz"),
"Download of Cmdstan failed. Please check if the supplied release URL is valid."
)
})


test_that("install_cmdstan() works with version and release_url", {
skip_if_offline()
if (getRversion() < '3.5.0') {
dir <- tempdir()
} else {
dir <- tempdir(check = TRUE)
}
expect_message(
expect_output(
install_cmdstan(dir = dir, overwrite = TRUE, cores = 4,
release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.24.0/cmdstan-2.24.0.tar.gz"),
"Compiling, linking C++ code",
fixed = TRUE
),
"Finished installing CmdStan"
)
expect_warning(
expect_message(
expect_output(
install_cmdstan(dir = dir, overwrite = TRUE, cores = 4,
version = "2.23.0",
# the URL is intentionally invalid to test that the version has higher priority
release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.23.2/cmdstan-2.23.2.tar.gz"),
"Compiling, linking C++ code",
fixed = TRUE
),
"Finished installing CmdStan"
),
"version and release_url are supplied to install_cmdstan()"
)
expect_true(dir.exists(file.path(dir, "cmdstan-2.23.0")))
})