@@ -528,19 +528,7 @@ compile <- function(quiet = TRUE,
528
528
warning(" 'compile_hessian_method' is deprecated. The hessian method is compiled with all models." )
529
529
}
530
530
531
- if (length(self $ exe_file()) == 0 ) {
532
- if (is.null(dir )) {
533
- exe_base <- self $ stan_file()
534
- } else {
535
- exe_base <- file.path(dir , basename(self $ stan_file()))
536
- }
537
- exe <- cmdstan_ext(strip_ext(exe_base ))
538
- if (dir.exists(exe )) {
539
- 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 )
540
- }
541
- } else {
542
- exe <- self $ exe_file()
543
- }
531
+ exe <- resolve_exe_path(dir , private $ dir_ , self $ exe_file(), self $ stan_file())
544
532
545
533
# Resolve stanc and cpp options
546
534
if (pedantic ) {
@@ -588,6 +576,7 @@ compile <- function(quiet = TRUE,
588
576
# - the executable does not exist
589
577
# - the stan model was changed since last compilation
590
578
# - a user header is used and the user header changed since last compilation (#813)
579
+ self $ exe_file(exe )
591
580
if (! file.exists(exe )) {
592
581
force_recompile <- TRUE
593
582
} else if (file.exists(self $ stan_file())
@@ -608,7 +597,6 @@ compile <- function(quiet = TRUE,
608
597
private $ precompile_stanc_options_ <- NULL
609
598
private $ precompile_include_paths_ <- NULL
610
599
self $ functions $ existing_exe <- TRUE
611
- self $ exe_file(exe )
612
600
return (invisible (self ))
613
601
} else {
614
602
if (rlang :: is_interactive()) {
@@ -2436,3 +2424,38 @@ model_compile_info <- function(exe_file, version) {
2436
2424
is_variables_method_supported <- function (mod ) {
2437
2425
cmdstan_version() > = " 2.27.0" && mod $ has_stan_file() && file.exists(mod $ stan_file())
2438
2426
}
2427
+ resolve_exe_path <- function (
2428
+ dir = NULL , private_dir = NULL , self_exe_file = NULL , self_stan_file = NULL
2429
+ ) {
2430
+ if (is.null(dir ) && ! is.null(private_dir )) {
2431
+ dir <- absolute_path(private_dir )
2432
+ } else if (! is.null(dir )) {
2433
+ dir <- absolute_path(dir )
2434
+ }
2435
+ if (! is.null(dir )) {
2436
+ dir <- repair_path(dir )
2437
+ assert_dir_exists(dir , access = " rw" )
2438
+ if (length(self_exe_file ) != 0 ) {
2439
+ self_exe_file <- file.path(dir , basename(self_exe_file ))
2440
+ }
2441
+ }
2442
+ if (length(self_exe_file ) == 0 ) {
2443
+ if (is.null(dir )) {
2444
+ exe_base <- self_stan_file
2445
+ } else {
2446
+ exe_base <- file.path(dir , basename(self_stan_file ))
2447
+ }
2448
+ exe <- cmdstan_ext(strip_ext(exe_base ))
2449
+ if (dir.exists(exe )) {
2450
+ stop(
2451
+ " There is a subfolder matching the model name " ,
2452
+ " in the same folder as the model! " ,
2453
+ " Please remove or rename the subfolder and try again." ,
2454
+ call. = FALSE
2455
+ )
2456
+ }
2457
+ } else {
2458
+ exe <- self_exe_file
2459
+ }
2460
+ exe
2461
+ }
0 commit comments