@@ -530,26 +530,24 @@ compile <- function(quiet = TRUE,
530
530
cpp_options [[" USER_HEADER" ]] <- wsl_safe_path(absolute_path(user_header ))
531
531
stanc_options [[" allow-undefined" ]] <- TRUE
532
532
private $ using_user_header_ <- TRUE
533
- }
534
- else if (! is.null(cpp_options [[" USER_HEADER" ]])) {
535
- if (! is.null(cpp_options [[" user_header" ]])) {
533
+ } else if (! is.null(cpp_options [[" USER_HEADER" ]])) {
534
+ if (! is.null(cpp_options [[" user_header" ]])) {
536
535
warning(' User header specified both via cpp_options[["USER_HEADER"]] and cpp_options[["user_header"]].' , call. = FALSE )
537
536
}
538
537
539
538
user_header <- cpp_options [[" USER_HEADER" ]]
540
539
cpp_options [[" USER_HEADER" ]] <- wsl_safe_path(absolute_path(cpp_options [[" USER_HEADER" ]]))
541
540
private $ using_user_header_ <- TRUE
542
- }
543
- else if (! is.null(cpp_options [[" user_header" ]])) {
541
+ } else if (! is.null(cpp_options [[" user_header" ]])) {
544
542
user_header <- cpp_options [[" user_header" ]]
545
543
cpp_options [[" user_header" ]] <- wsl_safe_path(absolute_path(cpp_options [[" user_header" ]]))
546
544
private $ using_user_header_ <- TRUE
547
545
}
548
546
549
547
550
- if (! is.null(user_header )) {
548
+ if (! is.null(user_header )) {
551
549
user_header <- absolute_path(user_header ) # As mentioned above, just absolute, not wsl_safe_path()
552
- if (! file.exists(user_header )) {
550
+ if (! file.exists(user_header )) {
553
551
stop(paste0(" User header file '" , user_header , " ' does not exist." ), call. = FALSE )
554
552
}
555
553
}
@@ -689,8 +687,12 @@ compile <- function(quiet = TRUE,
689
687
)
690
688
)
691
689
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 )
690
+ err_msg <- " An error occured during compilation! See the message above for more information."
691
+ if (grepl(" auto-format flag to stanc" , run_log $ stderr )) {
692
+ format_msg <- " \n To fix deprecated or removed syntax please see ?cmdstanr::format for an example."
693
+ err_msg <- paste(err_msg , format_msg )
694
+ }
695
+ stop(err_msg , call. = FALSE )
694
696
}
695
697
if (file.exists(exe )) {
696
698
file.remove(exe )
@@ -933,6 +935,28 @@ CmdStanModel$set("public", name = "check_syntax", value = check_syntax)
933
935
# '
934
936
# ' @examples
935
937
# ' \dontrun{
938
+ # '
939
+ # ' # Example of fixing old syntax
940
+ # ' # real x[2] --> array[2] real x;
941
+ # ' file <- write_stan_file("
942
+ # ' parameters {
943
+ # ' real x[2];
944
+ # ' }
945
+ # ' model {
946
+ # ' x ~ std_normal();
947
+ # ' }
948
+ # ' ")
949
+ # '
950
+ # ' # set compile=FALSE then call format to fix old syntax
951
+ # ' mod <- cmdstan_model(file, compile = FALSE)
952
+ # ' mod$format(canonicalize = list("deprecations"))
953
+ # '
954
+ # ' # overwrite the original file instead of just printing it
955
+ # ' mod$format(canonicalize = list("deprecations"), overwrite_file = TRUE)
956
+ # ' mod$compile()
957
+ # '
958
+ # '
959
+ # ' # Example of removing unnecessary whitespace
936
960
# ' file <- write_stan_file("
937
961
# ' data {
938
962
# ' int N;
0 commit comments