@@ -529,26 +529,24 @@ compile <- function(quiet = TRUE,
529529 cpp_options [[" USER_HEADER" ]] <- wsl_safe_path(absolute_path(user_header ))
530530 stanc_options [[" allow-undefined" ]] <- TRUE
531531 private $ using_user_header_ <- TRUE
532- }
533- else if (! is.null(cpp_options [[" USER_HEADER" ]])) {
534- if (! is.null(cpp_options [[" user_header" ]])) {
532+ } else if (! is.null(cpp_options [[" USER_HEADER" ]])) {
533+ if (! is.null(cpp_options [[" user_header" ]])) {
535534 warning(' User header specified both via cpp_options[["USER_HEADER"]] and cpp_options[["user_header"]].' , call. = FALSE )
536535 }
537536
538537 user_header <- cpp_options [[" USER_HEADER" ]]
539538 cpp_options [[" USER_HEADER" ]] <- wsl_safe_path(absolute_path(cpp_options [[" USER_HEADER" ]]))
540539 private $ using_user_header_ <- TRUE
541- }
542- else if (! is.null(cpp_options [[" user_header" ]])) {
540+ } else if (! is.null(cpp_options [[" user_header" ]])) {
543541 user_header <- cpp_options [[" user_header" ]]
544542 cpp_options [[" user_header" ]] <- wsl_safe_path(absolute_path(cpp_options [[" user_header" ]]))
545543 private $ using_user_header_ <- TRUE
546544 }
547545
548546
549- if (! is.null(user_header )) {
547+ if (! is.null(user_header )) {
550548 user_header <- absolute_path(user_header ) # As mentioned above, just absolute, not wsl_safe_path()
551- if (! file.exists(user_header )) {
549+ if (! file.exists(user_header )) {
552550 stop(paste0(" User header file '" , user_header , " ' does not exist." ), call. = FALSE )
553551 }
554552 }
@@ -688,8 +686,12 @@ compile <- function(quiet = TRUE,
688686 )
689687 )
690688 if (is.na(run_log $ status ) || run_log $ status != 0 ) {
691- stop(" An error occured during compilation! See the message above for more information." ,
692- call. = FALSE )
689+ err_msg <- " An error occured during compilation! See the message above for more information."
690+ if (grepl(" auto-format flag to stanc" , run_log $ stderr )) {
691+ format_msg <- " \n To fix deprecated or removed syntax please see ?cmdstanr::format for an example."
692+ err_msg <- paste(err_msg , format_msg )
693+ }
694+ stop(err_msg , call. = FALSE )
693695 }
694696 if (file.exists(exe )) {
695697 file.remove(exe )
@@ -932,6 +934,28 @@ CmdStanModel$set("public", name = "check_syntax", value = check_syntax)
932934# '
933935# ' @examples
934936# ' \dontrun{
937+ # '
938+ # ' # Example of fixing old syntax
939+ # ' # real x[2] --> array[2] real x;
940+ # ' file <- write_stan_file("
941+ # ' parameters {
942+ # ' real x[2];
943+ # ' }
944+ # ' model {
945+ # ' x ~ std_normal();
946+ # ' }
947+ # ' ")
948+ # '
949+ # ' # set compile=FALSE then call format to fix old syntax
950+ # ' mod <- cmdstan_model(file, compile = FALSE)
951+ # ' mod$format(canonicalize = list("deprecations"))
952+ # '
953+ # ' # overwrite the original file instead of just printing it
954+ # ' mod$format(canonicalize = list("deprecations"), overwrite_file = TRUE)
955+ # ' mod$compile()
956+ # '
957+ # '
958+ # ' # Example of removing unnecessary whitespace
935959# ' file <- write_stan_file("
936960# ' data {
937961# ' int N;
0 commit comments