@@ -3732,30 +3732,30 @@ load_model <- function(name, cache_dir = sccomp_stan_models_cache_dir, force=FAL
37323732# ' or asks for permission to install them in interactive sessions.
37333733# '
37343734# ' @importFrom instantiate stan_cmdstan_exists
3735- # ' @importFrom utils install.packages
3735+ # ' @importFrom rlang check_installed
37363736# ' @importFrom utils menu
37373737# ' @return NULL
37383738# '
37393739# ' @noRd
37403740check_and_install_cmdstanr <- function () {
3741+
37413742 # Check if cmdstanr is installed
3742- if (! requireNamespace(" cmdstanr" , quietly = TRUE )) {
3743-
3744- clear_stan_model_cache()
3745-
3746- stop(
3747- " cmdstanr is required to proceed.\n\n " ,
3748- " Step 1: Please install the R package 'cmdstanr' using the following command:\n " ,
3749- " install.packages(\" cmdstanr\" , repos = c(\" https://stan-dev.r-universe.dev/\" , getOption(\" repos\" )))\n " ,
3750- " Note: 'cmdstanr' is not available on CRAN.\n\n " ,
3751-
3752- " Step 2: After installing 'cmdstanr', you can install CmdStan by running the following commands:\n " ,
3753- " cmdstanr::check_cmdstan_toolchain(fix = TRUE)\n " ,
3754- " cmdstanr::install_cmdstan()\n " ,
3755- " This will install the latest version of CmdStan. For more information, visit:\n " ,
3756- " https://mc-stan.org/users/interfaces/cmdstan"
3757- )
3758- }
3743+ # from https://github.com/wlandau/instantiate/blob/33989d74c26f349e292e5efc11c267b3a1b71d3f/R/utils_assert.R#L114
3744+ tryCatch(
3745+ rlang :: check_installed(
3746+ pkg = " cmdstanr" ,
3747+ reason = paste(
3748+ " The {cmdstanr} package is required in order to install" ,
3749+ " CmdStan and run Stan models. Please install it manually using" ,
3750+ " install.packages(pkgs = \" cmdstanr\" ," ,
3751+ " repos = c(\" https://mc-stan.org/r-packages/\" , getOption(\" repos\" ))"
3752+ )
3753+ ),
3754+ error = function (e ) {
3755+ clear_stan_model_cache()
3756+ stan_error(conditionMessage(e ))
3757+ }
3758+ )
37593759
37603760 # Check if CmdStan is installed
37613761 if (! instantiate :: stan_cmdstan_exists()) {
0 commit comments