@@ -571,7 +571,7 @@ compile <- function(quiet = TRUE,
571571 }
572572
573573 if (! force_recompile ) {
574- if (interactive ()) {
574+ if (rlang :: is_interactive ()) {
575575 message(" Model executable is up to date!" )
576576 }
577577 private $ cpp_options_ <- cpp_options
@@ -582,7 +582,7 @@ compile <- function(quiet = TRUE,
582582 self $ exe_file(exe )
583583 return (invisible (self ))
584584 } else {
585- if (interactive ()) {
585+ if (rlang :: is_interactive ()) {
586586 message(" Compiling Stan program..." )
587587 }
588588 }
@@ -633,89 +633,92 @@ compile <- function(quiet = TRUE,
633633
634634 stancflags_val <- paste0(" STANCFLAGS += " , stancflags_val , paste0(" " , stancflags_combined , collapse = " " ))
635635
636- if (dry_run ) {
637- return (invisible (self ))
638- }
636+ if (! dry_run ) {
639637
640- if (compile_standalone ) {
641- expose_stan_functions(self $ functions , ! quiet )
642- }
638+ if (compile_standalone ) {
639+ expose_stan_functions(self $ functions , ! quiet )
640+ }
643641
644- withr :: with_path(
645- c(
646- toolchain_PATH_env_var(),
647- tbb_path()
648- ),
649- run_log <- wsl_compatible_run(
650- command = make_cmd(),
651- args = c(wsl_safe_path(tmp_exe ),
652- cpp_options_to_compile_flags(cpp_options ),
653- stancflags_val ),
654- wd = cmdstan_path(),
655- echo = ! quiet || is_verbose_mode(),
656- echo_cmd = is_verbose_mode(),
657- spinner = quiet && interactive() && ! identical(Sys.getenv(" IN_PKGDOWN" ), " true" ),
658- stderr_callback = function (x , p ) {
659- if (! startsWith(x , paste0(make_cmd(), " : *** No rule to make target" ))) {
660- message(x )
661- }
662- if (grepl(" PCH file" , x ) || grepl(" precompiled header" , x ) || grepl(" .hpp.gch" , x ) ) {
663- warning(
664- " CmdStan's precompiled header (PCH) files may need to be rebuilt.\n " ,
665- " If your model failed to compile please run rebuild_cmdstan().\n " ,
666- " If the issue persists please open a bug report." ,
667- call. = FALSE
668- )
669- }
670- if (grepl(" No space left on device" , x ) || grepl(" error in backend: IO failure on output stream" , x )) {
671- warning(
672- " The C++ compiler ran out of disk space and was unable to build the executables for your model!\n " ,
673- " See the above error for more details." ,
674- call. = FALSE
675- )
676- }
677- if (os_is_macos()) {
678- if (R.version $ arch == " aarch64"
679- && grepl(" but the current translation unit is being compiled for target" , x )) {
642+ withr :: with_path(
643+ c(
644+ toolchain_PATH_env_var(),
645+ tbb_path()
646+ ),
647+ run_log <- wsl_compatible_run(
648+ command = make_cmd(),
649+ args = c(wsl_safe_path(tmp_exe ),
650+ cpp_options_to_compile_flags(cpp_options ),
651+ stancflags_val ),
652+ wd = cmdstan_path(),
653+ echo = ! quiet || is_verbose_mode(),
654+ echo_cmd = is_verbose_mode(),
655+ spinner = quiet && rlang :: is_interactive() && ! identical(Sys.getenv(" IN_PKGDOWN" ), " true" ),
656+ stderr_callback = function (x , p ) {
657+ if (! startsWith(x , paste0(make_cmd(), " : *** No rule to make target" ))) {
658+ message(x )
659+ }
660+ if (grepl(" PCH file" , x ) || grepl(" precompiled header" , x ) || grepl(" .hpp.gch" , x ) ) {
680661 warning(
681- " The C++ compiler has errored due to incompatibility between the x86 and " ,
682- " Apple Silicon architectures.\n " ,
683- " If you are running R inside an IDE (RStudio, VSCode, ...), " ,
684- " make sure the IDE is a native Apple Silicon app.\n " ,
662+ " CmdStan's precompiled header (PCH) files may need to be rebuilt.\n " ,
663+ " If your model failed to compile please run rebuild_cmdstan().\n " ,
664+ " If the issue persists please open a bug report." ,
685665 call. = FALSE
686666 )
687667 }
688- }
689- },
690- error_on_status = FALSE
691- )
692- )
693- if (is.na(run_log $ status ) || run_log $ status != 0 ) {
694- stop(" An error occured during compilation! See the message above for more information." ,
695- call. = FALSE )
696- }
697- if (file.exists(exe )) {
698- file.remove(exe )
699- }
700- file.copy(tmp_exe , exe , overwrite = TRUE )
701- if (os_is_wsl()) {
702- res <- processx :: run(
703- command = " wsl" ,
704- args = c(" chmod" , " +x" , wsl_safe_path(exe )),
705- error_on_status = FALSE
668+ if (grepl(" No space left on device" , x ) || grepl(" error in backend: IO failure on output stream" , x )) {
669+ warning(
670+ " The C++ compiler ran out of disk space and was unable to build the executables for your model!\n " ,
671+ " See the above error for more details." ,
672+ call. = FALSE
673+ )
674+ }
675+ if (os_is_macos()) {
676+ if (R.version $ arch == " aarch64"
677+ && grepl(" but the current translation unit is being compiled for target" , x )) {
678+ warning(
679+ " The C++ compiler has errored due to incompatibility between the x86 and " ,
680+ " Apple Silicon architectures.\n " ,
681+ " If you are running R inside an IDE (RStudio, VSCode, ...), " ,
682+ " make sure the IDE is a native Apple Silicon app.\n " ,
683+ call. = FALSE
684+ )
685+ }
686+ }
687+ },
688+ error_on_status = FALSE
689+ )
706690 )
707- }
691+ if (is.na(run_log $ status ) || run_log $ status != 0 ) {
692+ stop(" An error occured during compilation! See the message above for more information." ,
693+ call. = FALSE )
694+ }
695+ if (file.exists(exe )) {
696+ file.remove(exe )
697+ }
698+ file.copy(tmp_exe , exe , overwrite = TRUE )
699+ if (os_is_wsl()) {
700+ res <- processx :: run(
701+ command = " wsl" ,
702+ args = c(" chmod" , " +x" , wsl_safe_path(exe )),
703+ error_on_status = FALSE
704+ )
705+ }
706+ } # End - if(!dry_run)
707+
708708 private $ exe_file_ <- exe
709709 private $ cpp_options_ <- cpp_options
710710 private $ precompile_cpp_options_ <- NULL
711711 private $ precompile_stanc_options_ <- NULL
712712 private $ precompile_include_paths_ <- NULL
713713 private $ model_methods_env_ <- new.env()
714- suppressWarnings(private $ model_methods_env_ $ hpp_code_ <- readLines(private $ hpp_file_ , warn = FALSE ))
715- if (compile_model_methods ) {
716- expose_model_methods(env = private $ model_methods_env_ ,
717- verbose = ! quiet ,
718- hessian = compile_hessian_method )
714+
715+ if (! dry_run ) {
716+ suppressWarnings(private $ model_methods_env_ $ hpp_code_ <- readLines(private $ hpp_file_ , warn = FALSE ))
717+ if (compile_model_methods ) {
718+ expose_model_methods(env = private $ model_methods_env_ ,
719+ verbose = ! quiet ,
720+ hessian = compile_hessian_method )
721+ }
719722 }
720723 invisible (self )
721724}
@@ -807,7 +810,7 @@ CmdStanModel$set("public", name = "variables", value = variables)
807810# ' file <- write_stan_file("
808811# ' data {
809812# ' int N;
810- # ' int y [N];
813+ # ' array [N] int y ;
811814# ' }
812815# ' parameters {
813816# ' // should have <lower=0> but omitting to demonstrate pedantic mode
@@ -877,7 +880,7 @@ check_syntax <- function(pedantic = FALSE,
877880 wd = cmdstan_path(),
878881 echo = is_verbose_mode(),
879882 echo_cmd = is_verbose_mode(),
880- spinner = quiet && interactive (),
883+ spinner = quiet && rlang :: is_interactive (),
881884 stderr_callback = function (x , p ) {
882885 message(x )
883886 },
@@ -933,7 +936,7 @@ CmdStanModel$set("public", name = "check_syntax", value = check_syntax)
933936# ' file <- write_stan_file("
934937# ' data {
935938# ' int N;
936- # ' int y [N];
939+ # ' array [N] int y ;
937940# ' }
938941# ' parameters {
939942# ' real lambda;
@@ -1829,7 +1832,7 @@ CmdStanModel$set("public", name = "variational", value = variational)
18291832# ' mcmc_program <- write_stan_file(
18301833# ' "data {
18311834# ' int<lower=0> N;
1832- # ' int<lower=0,upper=1> y[N] ;
1835+ # ' array[N] int<lower=0,upper=1> y;
18331836# ' }
18341837# ' parameters {
18351838# ' real<lower=0,upper=1> theta;
@@ -1848,13 +1851,13 @@ CmdStanModel$set("public", name = "variational", value = variational)
18481851# ' gq_program <- write_stan_file(
18491852# ' "data {
18501853# ' int<lower=0> N;
1851- # ' int<lower=0,upper=1> y[N] ;
1854+ # ' array[N] int<lower=0,upper=1> y;
18521855# ' }
18531856# ' parameters {
18541857# ' real<lower=0,upper=1> theta;
18551858# ' }
18561859# ' generated quantities {
1857- # ' int y_rep [N] = bernoulli_rng(rep_vector(theta, N));
1860+ # ' array [N] int y_rep = bernoulli_rng(rep_vector(theta, N));
18581861# ' }"
18591862# ' )
18601863# '
0 commit comments