@@ -275,25 +275,9 @@ CmdStanModel <- R6::R6Class(
275
275
if (! is.null(stan_file ) && compile ) {
276
276
self $ compile(... )
277
277
} 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 )
297
281
298
282
# exe_info is updated inside the compile method (if compile command is run)
299
283
self $ exe_info(update = TRUE )
@@ -597,18 +581,6 @@ compile <- function(quiet = TRUE,
597
581
include_paths <- private $ precompile_include_paths_
598
582
}
599
583
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
- }
612
584
613
585
# temporary deprecation warnings
614
586
if (isTRUE(threads )) {
@@ -2437,6 +2409,7 @@ model_variables <- function(stan_file, include_paths = NULL, allow_undefined = F
2437
2409
is_variables_method_supported <- function (mod ) {
2438
2410
cmdstan_version() > = " 2.27.0" && mod $ has_stan_file() && file.exists(mod $ stan_file())
2439
2411
}
2412
+
2440
2413
resolve_exe_path <- function (
2441
2414
dir = NULL , private_dir = NULL , self_exe_file = NULL , self_stan_file = NULL
2442
2415
) {
0 commit comments