I’m trying to capture the error message accompanying a failed model compilation (for other uses). Interactively
> stan_model(file='stan_programs/debug.stan')
returns something like
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:
real[ ] * real[ ]
...
Explicitly capturing the error output prints the error message to screen,
> output <- capture.output(stan_model(file='stan_programs/debug.stan'), type=c("message"))
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:
real[ ] * real[ ]
...
but doesn’t capture it,
> output
NULL
Similarly a tryCatch still lets the same error message be print to screen,
> output <- tryCatch({stan_model(file='stan_programs/debug.stan')},
error = function(e) { return(e) })
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:
real[ ] * real[ ]
...
in this case capturing a different error,
> result
<simpleError in stanc(file = file, model_code = model_code, model_name = model_name, verbose = verbose, obfuscate_model_name = obfuscate_model_name, allow_undefined = allow_undefined, isystem = isystem): failed to parse Stan model 'debug1a' due to the above error.>
From the RStan
repository it looks like the message being printed to screen and evading all means of capture is coming from a C++ exception thrown but I can’t figure out how rcpp
is handling that and what kind of message it produces.
Does anyone have any idea how to capture these error messages so that I can reformat them and the like?
Thanks.
- Operating System - OS X 10.14
- RStan Version - 2.192.