Skip to content

Commit 6cce506

Browse files
committed
move exe file path resolution to separate function
1 parent 767ede9 commit 6cce506

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

R/model.R

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,9 @@ CmdStanModel <- R6::R6Class(
275275
if (!is.null(stan_file) && compile) {
276276
self$compile(...)
277277
} else {
278-
# set exe path, same logic as in compile
279-
if(!is.null(private$dir_)){
280-
dir <- repair_path(absolute_path(private$dir_))
281-
assert_dir_exists(dir, access = "rw")
282-
if (length(self$exe_file()) != 0) {
283-
self$exe_file(file.path(dir, basename(self$exe_file())))
284-
}
285-
}
286-
if (length(self$exe_file()) == 0) {
287-
if (is.null(private$dir_)) {
288-
exe_base <- self$stan_file()
289-
} else {
290-
exe_base <- file.path(private$dir_, basename(self$stan_file()))
291-
}
292-
self$exe_file(cmdstan_ext(strip_ext(exe_base)))
293-
if (dir.exists(self$exe_file())) {
294-
stop("There is a subfolder matching the model name in the same folder as the model! Please remove or rename the subfolder and try again.", call. = FALSE)
295-
}
296-
}
278+
# resolve exe path with dir
279+
exe <- resolve_exe_path(args$dir, private$dir_, self$exe_file(), self$stan_file())
280+
self$exe_file(exe)
297281

298282
# exe_info is updated inside the compile method (if compile command is run)
299283
self$exe_info(update = TRUE)
@@ -597,18 +581,6 @@ compile <- function(quiet = TRUE,
597581
include_paths <- private$precompile_include_paths_
598582
}
599583
private$include_paths_ <- include_paths
600-
if (is.null(dir) && !is.null(private$dir_)) {
601-
dir <- absolute_path(private$dir_)
602-
} else if (!is.null(dir)) {
603-
dir <- absolute_path(dir)
604-
}
605-
if (!is.null(dir)) {
606-
dir <- repair_path(dir)
607-
assert_dir_exists(dir, access = "rw")
608-
if (length(self$exe_file()) != 0) {
609-
private$exe_file_ <- file.path(dir, basename(self$exe_file()))
610-
}
611-
}
612584

613585
# temporary deprecation warnings
614586
if (isTRUE(threads)) {
@@ -2437,6 +2409,7 @@ model_variables <- function(stan_file, include_paths = NULL, allow_undefined = F
24372409
is_variables_method_supported <- function(mod) {
24382410
cmdstan_version() >= "2.27.0" && mod$has_stan_file() && file.exists(mod$stan_file())
24392411
}
2412+
24402413
resolve_exe_path <- function(
24412414
dir = NULL, private_dir = NULL, self_exe_file = NULL, self_stan_file = NULL
24422415
) {

0 commit comments

Comments
 (0)