@@ -568,7 +568,7 @@ compile <- function(quiet = TRUE,
568568 }
569569
570570 if (! force_recompile ) {
571- if (interactive ()) {
571+ if (rlang :: is_interactive ()) {
572572 message(" Model executable is up to date!" )
573573 }
574574 private $ cpp_options_ <- cpp_options
@@ -579,7 +579,7 @@ compile <- function(quiet = TRUE,
579579 self $ exe_file(exe )
580580 return (invisible (self ))
581581 } else {
582- if (interactive ()) {
582+ if (rlang :: is_interactive ()) {
583583 message(" Compiling Stan program..." )
584584 }
585585 }
@@ -630,93 +630,92 @@ compile <- function(quiet = TRUE,
630630
631631 stancflags_val <- paste0(" STANCFLAGS += " , stancflags_val , paste0(" " , stancflags_combined , collapse = " " ))
632632
633- if (dry_run ) {
634- return (invisible (self ))
635- }
633+ if (! dry_run ) {
636634
637- if (compile_standalone ) {
638- expose_stan_functions(self $ functions , ! quiet )
639- }
635+ if (compile_standalone ) {
636+ expose_stan_functions(self $ functions , ! quiet )
637+ }
640638
641- withr :: with_path(
642- c(
643- toolchain_PATH_env_var(),
644- tbb_path()
645- ),
646- run_log <- wsl_compatible_run(
647- command = make_cmd(),
648- args = c(wsl_safe_path(tmp_exe ),
649- cpp_options_to_compile_flags(cpp_options ),
650- stancflags_val ),
651- wd = cmdstan_path(),
652- echo = ! quiet || is_verbose_mode(),
653- echo_cmd = is_verbose_mode(),
654- spinner = quiet && interactive() && ! identical(Sys.getenv(" IN_PKGDOWN" ), " true" ),
655- stderr_callback = function (x , p ) {
656- if (! startsWith(x , paste0(make_cmd(), " : *** No rule to make target" ))) {
657- message(x )
658- }
659- if (grepl(" PCH file" , x ) || grepl(" precompiled header" , x ) || grepl(" .hpp.gch" , x ) ) {
660- warning(
661- " CmdStan's precompiled header (PCH) files may need to be rebuilt.\n " ,
662- " If your model failed to compile please run rebuild_cmdstan().\n " ,
663- " If the issue persists please open a bug report." ,
664- call. = FALSE
665- )
666- }
667- if (grepl(" No space left on device" , x ) || grepl(" error in backend: IO failure on output stream" , x )) {
668- warning(
669- " The C++ compiler ran out of disk space and was unable to build the executables for your model!\n " ,
670- " See the above error for more details." ,
671- call. = FALSE
672- )
673- }
674- if (os_is_macos()) {
675- if (R.version $ arch == " aarch64"
676- && grepl(" but the current translation unit is being compiled for target" , x )) {
639+ withr :: with_path(
640+ c(
641+ toolchain_PATH_env_var(),
642+ tbb_path()
643+ ),
644+ run_log <- wsl_compatible_run(
645+ command = make_cmd(),
646+ args = c(wsl_safe_path(tmp_exe ),
647+ cpp_options_to_compile_flags(cpp_options ),
648+ stancflags_val ),
649+ wd = cmdstan_path(),
650+ echo = ! quiet || is_verbose_mode(),
651+ echo_cmd = is_verbose_mode(),
652+ spinner = quiet && rlang :: is_interactive() && ! identical(Sys.getenv(" IN_PKGDOWN" ), " true" ),
653+ stderr_callback = function (x , p ) {
654+ if (! startsWith(x , paste0(make_cmd(), " : *** No rule to make target" ))) {
655+ message(x )
656+ }
657+ if (grepl(" PCH file" , x ) || grepl(" precompiled header" , x ) || grepl(" .hpp.gch" , x ) ) {
677658 warning(
678- " The C++ compiler has errored due to incompatibility between the x86 and " ,
679- " Apple Silicon architectures.\n " ,
680- " If you are running R inside an IDE (RStudio, VSCode, ...), " ,
681- " make sure the IDE is a native Apple Silicon app.\n " ,
659+ " CmdStan's precompiled header (PCH) files may need to be rebuilt.\n " ,
660+ " If your model failed to compile please run rebuild_cmdstan().\n " ,
661+ " If the issue persists please open a bug report." ,
682662 call. = FALSE
683663 )
684664 }
685- }
686- },
687- error_on_status = FALSE
665+ if (grepl(" No space left on device" , x ) || grepl(" error in backend: IO failure on output stream" , x )) {
666+ warning(
667+ " The C++ compiler ran out of disk space and was unable to build the executables for your model!\n " ,
668+ " See the above error for more details." ,
669+ call. = FALSE
670+ )
671+ }
672+ if (os_is_macos()) {
673+ if (R.version $ arch == " aarch64"
674+ && grepl(" but the current translation unit is being compiled for target" , x )) {
675+ warning(
676+ " The C++ compiler has errored due to incompatibility between the x86 and " ,
677+ " Apple Silicon architectures.\n " ,
678+ " If you are running R inside an IDE (RStudio, VSCode, ...), " ,
679+ " make sure the IDE is a native Apple Silicon app.\n " ,
680+ call. = FALSE
681+ )
682+ }
683+ }
684+ },
685+ error_on_status = FALSE
686+ )
688687 )
689- )
690- if (is.na(run_log $ status ) || run_log $ status != 0 ) {
691- err_msg <- " An error occured during compilation! See the message above for more information."
692- if (grepl(" auto-format flag to stanc" , run_log $ stderr )) {
693- format_msg <- " \n To fix deprecated or removed syntax please see ?cmdstanr::format for an example."
694- err_msg <- paste(err_msg , format_msg )
688+ if (is.na(run_log $ status ) || run_log $ status != 0 ) {
689+ stop(" An error occured during compilation! See the message above for more information." ,
690+ call. = FALSE )
695691 }
696- stop( err_msg , call. = FALSE )
697- }
698- if (file.exists( exe )) {
699- file.remove( exe )
700- }
701- file.copy( tmp_exe , exe , overwrite = TRUE )
702- if (os_is_wsl()) {
703- res <- processx :: run(
704- command = " wsl " ,
705- args = c( " chmod " , " +x " , wsl_safe_path( exe )),
706- error_on_status = FALSE
707- )
708- }
692+ if (file.exists( exe )) {
693+ file.remove( exe )
694+ }
695+ file.copy( tmp_exe , exe , overwrite = TRUE )
696+ if (os_is_wsl()) {
697+ res <- processx :: run(
698+ command = " wsl " ,
699+ args = c( " chmod " , " +x " , wsl_safe_path( exe )),
700+ error_on_status = FALSE
701+ )
702+ }
703+ } # End - if(!dry_run )
704+
709705 private $ exe_file_ <- exe
710706 private $ cpp_options_ <- cpp_options
711707 private $ precompile_cpp_options_ <- NULL
712708 private $ precompile_stanc_options_ <- NULL
713709 private $ precompile_include_paths_ <- NULL
714710 private $ model_methods_env_ <- new.env()
715- suppressWarnings(private $ model_methods_env_ $ hpp_code_ <- readLines(private $ hpp_file_ , warn = FALSE ))
716- if (compile_model_methods ) {
717- expose_model_methods(env = private $ model_methods_env_ ,
718- verbose = ! quiet ,
719- hessian = compile_hessian_method )
711+
712+ if (! dry_run ) {
713+ suppressWarnings(private $ model_methods_env_ $ hpp_code_ <- readLines(private $ hpp_file_ , warn = FALSE ))
714+ if (compile_model_methods ) {
715+ expose_model_methods(env = private $ model_methods_env_ ,
716+ verbose = ! quiet ,
717+ hessian = compile_hessian_method )
718+ }
720719 }
721720 invisible (self )
722721}
@@ -878,7 +877,7 @@ check_syntax <- function(pedantic = FALSE,
878877 wd = cmdstan_path(),
879878 echo = is_verbose_mode(),
880879 echo_cmd = is_verbose_mode(),
881- spinner = quiet && interactive (),
880+ spinner = quiet && rlang :: is_interactive (),
882881 stderr_callback = function (x , p ) {
883882 message(x )
884883 },
0 commit comments