Skip to content

Commit 6023217

Browse files
committed
update the check of cmdstanr installation
1 parent 7fb79b0 commit 6023217

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ importFrom(readr,read_file)
100100
importFrom(readr,type_convert)
101101
importFrom(readr,write_file)
102102
importFrom(rlang,":=")
103+
importFrom(rlang,abort)
103104
importFrom(rlang,check_installed)
104105
importFrom(rlang,enquo)
105106
importFrom(rlang,ensym)
@@ -143,4 +144,3 @@ importFrom(tidyselect,all_of)
143144
importFrom(tidyselect,eval_select)
144145
importFrom(tidyselect,last_col)
145146
importFrom(utils,data)
146-
importFrom(utils,menu)

R/utilities.R

+18-2
Original file line numberDiff line numberDiff line change
@@ -3743,14 +3743,30 @@ load_model <- function(name, cache_dir = sccomp_stan_models_cache_dir, force=FAL
37433743
#'
37443744
#' @importFrom instantiate stan_cmdstan_exists
37453745
#' @importFrom rlang check_installed
3746-
#' @importFrom utils menu
3746+
#' @importFrom rlang abort
3747+
#' @importFrom rlang check_installed
37473748
#' @return NULL
37483749
#'
37493750
#' @noRd
37503751
check_and_install_cmdstanr <- function() {
37513752

37523753
# Check if cmdstanr is installed
37533754
# from https://github.com/wlandau/instantiate/blob/33989d74c26f349e292e5efc11c267b3a1b71d3f/R/utils_assert.R#L114
3755+
3756+
stan_error <- function(message = NULL) {
3757+
stan_stop(
3758+
message = message,
3759+
class = c("stan_error", "stan")
3760+
)
3761+
}
3762+
3763+
stan_stop <- function(message, class) {
3764+
old <- getOption("rlang_backtrace_on_error")
3765+
on.exit(options(rlang_backtrace_on_error = old))
3766+
options(rlang_backtrace_on_error = "none")
3767+
abort(message = message, class = class, call = emptyenv())
3768+
}
3769+
37543770
tryCatch(
37553771
rlang::check_installed(
37563772
pkg = "cmdstanr",
@@ -3768,7 +3784,7 @@ check_and_install_cmdstanr <- function() {
37683784
)
37693785

37703786
# Check if CmdStan is installed
3771-
if (!instantiate::stan_cmdstan_exists()) {
3787+
if (!stan_cmdstan_exists()) {
37723788

37733789
clear_stan_model_cache()
37743790

0 commit comments

Comments
 (0)