Skip to content

Commit

Permalink
Migrate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Jan 9, 2024
1 parent 7da32dc commit 1b2d640
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
12 changes: 9 additions & 3 deletions R/stan_cmdstan_exists.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#' @title Check if `instantiate` can find CmdStan.
#' @title Check if `instantiate` can find CmdStanR and CmdStan.
#' @export
#' @family cmdstan
#' @description Check if `instantiate` can find CmdStan.
#' @description Check if `instantiate` can find CmdStanR and CmdStan.
#' @inheritParams stan_cmdstan_path
#' @return `TRUE` if `instantiate` can find CmdStan, `FALSE` otherwise.
#' @return `TRUE` if `instantiate` can find the CmdStanR R package and the
#' CmdStan command line tool. Returns `FALSE` otherwise.
#' @examples
#' stan_cmdstan_exists()
stan_cmdstan_exists <- function(
cmdstan_install = Sys.getenv("CMDSTAN_INSTALL", unset = "")
) {
# nocov start
if (!rlang::is_installed("cmdstanr")) {
return(FALSE) # Not possible to cover in regular unit tests.
}
# nocov end
path <- stan_cmdstan_path(cmdstan_install = cmdstan_install)
cmdstan_valid(path)
}
Expand Down
7 changes: 6 additions & 1 deletion R/stan_cmdstan_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
stan_cmdstan_path <- function(
cmdstan_install = Sys.getenv("CMDSTAN_INSTALL", unset = "")
) {
# nocov start
if (!rlang::is_installed("cmdstanr")) {
return("") # Not possible to cover in regular unit tests.
}
# nocov end
install <- if_any(
identical(cmdstan_install, ""),
.Call(c_cmdstan_path_install, PACKAGE = "instantiate"),
Expand All @@ -44,5 +49,5 @@ stan_cmdstan_path <- function(
cmdstan_valid(path),
path,
cmdstanr("cmdstan_default_path")(dir = path)
) %|||% NULL
) %|||% ""
}
3 changes: 2 additions & 1 deletion R/stan_cmdstan_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#' package uses. If CmdStan is not found, then the return value depends
#' on the `error_on_NA` argument.
#' @inheritParams stan_cmdstan_path
#' @inheritParams cmdstanr::cmdstan_version
#' @param error_on_NA Logical of length 1, whether an error should be thrown
#' if CmdStan is not found.
#' @examples
#' if (stan_cmdstan_exists()) {
#' message(stan_cmdstan_version())
Expand Down
7 changes: 4 additions & 3 deletions man/stan_cmdstan_exists.Rd

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

5 changes: 2 additions & 3 deletions man/stan_cmdstan_version.Rd

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

0 comments on commit 1b2d640

Please sign in to comment.