The $check_syntax() method of a CmdStanModel object
checks the Stan program for syntax errors and returns TRUE (invisibly) if
parsing succeeds. If invalid syntax is found an error is thrown.
The standalone function check_syntax_stan_file() does the same for a Stan
program without creating a model object, and so without compiling it.
Arguments
- pedantic
(logical) Should pedantic mode be turned on? The default is
FALSE. Pedantic mode attempts to warn you about potential issues in your Stan program beyond syntax errors. For details see the Pedantic mode chapter in the Stan User's Guide.- include_paths
(character vector) Paths to directories where Stan should look for files specified in
#includedirectives in the Stan program. The method uses the model's own include paths when none are given.check_syntax_stan_file()uses the program's own directory when none are given and the program contains#includedirectives.- stanc_options
(list) Any other options for stanc, the Stan compiler. See the documentation for
cmdstan_model()for details.- quiet
(logical) Should informational messages be suppressed? The default is
FALSE, which will print a message if the Stan program is valid or the compiler error message if there are syntax errors. IfTRUE, only the error message will be printed.- stan_file
(string) The path to a Stan program.
See also
The CmdStanR website (mc-stan.org/cmdstanr) for online documentation and tutorials.
The Stan and CmdStan documentation:
Stan documentation: mc-stan.org/users/documentation
CmdStan User’s Guide: mc-stan.org/docs/cmdstan-guide
Other CmdStanModel methods:
model-method-build_info,
model-method-cmdstan_defaults,
model-method-diagnose,
model-method-expose_functions,
model-method-format,
model-method-generate-quantities,
model-method-is_current,
model-method-laplace,
model-method-model-info,
model-method-optimize,
model-method-pathfinder,
model-method-sample,
model-method-sample_mpi,
model-method-variables,
model-method-variational
Examples
# \dontrun{
file <- write_stan_file("
data {
int N;
array[N] int y;
}
parameters {
// should have <lower=0> but omitting to demonstrate pedantic mode
real lambda;
}
model {
y ~ poisson(lambda);
}
")
mod <- cmdstan_model(file)
# the program is syntactically correct, however...
mod$check_syntax()
#> Stan program is syntactically correct
# pedantic mode will warn that lambda should be constrained to be positive
# and that lambda has no prior distribution
mod$check_syntax(pedantic = TRUE)
#> Warning in '/tmp/RtmpwHIm89/model_287cd4f50e093cb87805d29fd774bdf8.stan', line 8, column 2 to column 14:
#> The parameter lambda has no priors. This means either no prior is
#> provided, or the prior(s) depend on data variables. In the later case,
#> this may be a false positive.
#> Warning in '/tmp/RtmpwHIm89/model_287cd4f50e093cb87805d29fd774bdf8.stan', line 11, column 14 to column 20:
#> A poisson distribution is given parameter lambda as a rate parameter
#> (argument 1), but lambda was not constrained to be strictly positive.
#> Stan program is syntactically correct
# }