@@ -530,26 +530,24 @@ compile <- function(quiet = TRUE,
530530 cpp_options [[" USER_HEADER" ]] <- wsl_safe_path(absolute_path(user_header ))
531531 stanc_options [[" allow-undefined" ]] <- TRUE
532532 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" ]])) {
536535 warning(' User header specified both via cpp_options[["USER_HEADER"]] and cpp_options[["user_header"]].' , call. = FALSE )
537536 }
538537
539538 user_header <- cpp_options [[" USER_HEADER" ]]
540539 cpp_options [[" USER_HEADER" ]] <- wsl_safe_path(absolute_path(cpp_options [[" USER_HEADER" ]]))
541540 private $ using_user_header_ <- TRUE
542- }
543- else if (! is.null(cpp_options [[" user_header" ]])) {
541+ } else if (! is.null(cpp_options [[" user_header" ]])) {
544542 user_header <- cpp_options [[" user_header" ]]
545543 cpp_options [[" user_header" ]] <- wsl_safe_path(absolute_path(cpp_options [[" user_header" ]]))
546544 private $ using_user_header_ <- TRUE
547545 }
548546
549547
550- if (! is.null(user_header )) {
548+ if (! is.null(user_header )) {
551549 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 )) {
553551 stop(paste0(" User header file '" , user_header , " ' does not exist." ), call. = FALSE )
554552 }
555553 }
@@ -689,8 +687,12 @@ compile <- function(quiet = TRUE,
689687 )
690688 )
691689 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 )
694696 }
695697 if (file.exists(exe )) {
696698 file.remove(exe )
@@ -933,6 +935,28 @@ CmdStanModel$set("public", name = "check_syntax", value = check_syntax)
933935# '
934936# ' @examples
935937# ' \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
936960# ' file <- write_stan_file("
937961# ' data {
938962# ' int N;
0 commit comments