Skip to content

Commit a3d1d22

Browse files
committed
refactor and simplify code, make sure no unncessary warnings are displayed
1 parent d3234fe commit a3d1d22

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

R/path.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ cmdstan_version <- function(error_on_NA = TRUE) {
8585
# number, and path to temp dir
8686
.cmdstanr <- new.env(parent = emptyenv())
8787
.cmdstanr$PATH <- NULL
88-
.cmdstanr$INSTALL_FOLDER <- NULL
8988
.cmdstanr$VERSION <- NULL
9089
.cmdstanr$TEMP_DIR <- NULL
9190

@@ -110,14 +109,10 @@ stop_no_path <- function() {
110109
#' @return The installation path.
111110
#' @export
112111
cmdstan_default_install_path <- function(old = FALSE) {
113-
if (!is.null(.cmdstanr$INSTALL_FOLDER)) {
114-
.cmdstanr$INSTALL_FOLDER
112+
if (old) {
113+
file.path(Sys.getenv("HOME"), ".cmdstanr")
115114
} else {
116-
if (old) {
117-
file.path(Sys.getenv("HOME"), ".cmdstanr")
118-
} else {
119-
file.path(Sys.getenv("HOME"), ".cmdstan")
120-
}
115+
file.path(Sys.getenv("HOME"), ".cmdstan")
121116
}
122117
}
123118

@@ -129,11 +124,16 @@ cmdstan_default_install_path <- function(old = FALSE) {
129124
#' @export
130125
#' @keywords internal
131126
#' @param old See [cmdstan_default_install_path()].
127+
#' @param dir Path to a custom install folder with CmdStan installations.
132128
#' @return Path to the CmdStan installation with the most recent release
133129
#' version, or `NULL` if no installation found.
134130
#'
135-
cmdstan_default_path <- function(old = FALSE) {
136-
installs_path <- cmdstan_default_install_path(old)
131+
cmdstan_default_path <- function(old = FALSE, dir = NULL) {
132+
if (!is.null(dir)) {
133+
installs_path <- dir
134+
} else {
135+
installs_path <- cmdstan_default_install_path(old)
136+
}
137137
if (dir.exists(installs_path)) {
138138
cmdstan_installs <- list.dirs(path = installs_path, recursive = FALSE, full.names = FALSE)
139139
# if installed in cmdstan folder with no version move to cmdstan-version folder

R/zzz.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,19 @@ cmdstanr_initialize <- function() {
3434
if (isTRUE(nzchar(path))) { # CMDSTAN environment variable found
3535
if (dir.exists(path)) {
3636
path <- absolute_path(path)
37-
suppressMessages(set_cmdstan_path(path))
37+
suppressWarnings(suppressMessages(set_cmdstan_path(path)))
3838
if (is.null(cmdstan_version(error_on_NA = FALSE))) {
39-
.cmdstanr$INSTALL_FOLDER <- path
40-
set_cmdstan_path()
39+
path <- cmdstan_default_path(dir = path)
40+
if (is.null(path)) {
41+
warning(
42+
"No CmdStan installation found in the path specified ",
43+
"by the environment variable 'CMDSTAN'.",
44+
call. = FALSE
45+
)
46+
.cmdstanr$PATH <- NULL
47+
} else {
48+
set_cmdstan_path(path)
49+
}
4150
}
4251
} else {
4352
warning(

man/cmdstan_default_path.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)