Skip to content

Commit bd71201

Browse files
authored
Merge pull request #171 from MangiolaLaboratory/fix-cmdstanr-depedency-2
change the way I check package
2 parents 1b35dc8 + b9d9362 commit bd71201

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ importFrom(readr,read_file)
9797
importFrom(readr,type_convert)
9898
importFrom(readr,write_file)
9999
importFrom(rlang,":=")
100+
importFrom(rlang,check_installed)
100101
importFrom(rlang,enquo)
101102
importFrom(rlang,ensym)
102103
importFrom(rlang,inform)
@@ -139,5 +140,4 @@ importFrom(tidyselect,all_of)
139140
importFrom(tidyselect,eval_select)
140141
importFrom(tidyselect,last_col)
141142
importFrom(utils,data)
142-
importFrom(utils,install.packages)
143143
importFrom(utils,menu)

R/utilities.R

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
37403740
check_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

Comments
 (0)