@@ -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 }
@@ -690,8 +688,12 @@ compile <- function(quiet = TRUE,
690688 )
691689 )
692690 if (is.na(run_log $ status ) || run_log $ status != 0 ) {
693- stop(" An error occured during compilation! See the message above for more information." ,
694- call. = FALSE )
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 )
695+ }
696+ stop(err_msg , call. = FALSE )
695697 }
696698 if (file.exists(exe )) {
697699 file.remove(exe )
@@ -929,6 +931,21 @@ CmdStanModel$set("public", name = "check_syntax", value = check_syntax)
929931# '
930932# ' @examples
931933# ' \dontrun{
934+ # '
935+ # ' # Example of fixing old syntax
936+ # ' # real x[2] --> array[2] real x;
937+ # ' file <- write_stan_file("
938+ # ' parameters {
939+ # ' real x[2];
940+ # ' }
941+ # ' model {
942+ # ' x ~ std_normal();
943+ # ' }
944+ # ' ")
945+ # ' mod <- cmdstan_model(file, compile = FALSE)
946+ # ' mod$format(canonicalize = TRUE)
947+ # '
948+ # ' # Example of removing unnecessary whitespace
932949# ' file <- write_stan_file("
933950# ' data {
934951# ' int N;
0 commit comments