model-method-format | R Documentation |
The $format()
method of a CmdStanModel
object
runs stanc's auto-formatter on the model code. Either saves the formatted
model directly back to the file or prints it for inspection.
format(
overwrite_file = FALSE,
canonicalize = FALSE,
backup = TRUE,
max_line_length = NULL,
quiet = FALSE
)
overwrite_file |
(logical) Should the formatted code be written back
to the input model file. The default is |
canonicalize |
(list or logical) Defines whether or not the compiler
should 'canonicalize' the Stan model, removing things like deprecated syntax.
Default is |
backup |
(logical) If |
max_line_length |
(integer) The maximum length of a line when formatting.
The default is |
quiet |
(logical) Should informational messages be suppressed? The
default is |
The $format()
method returns TRUE
(invisibly) if the model
is valid.
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-check_syntax
,
model-method-compile
,
model-method-diagnose
,
model-method-expose_functions
,
model-method-generate-quantities
,
model-method-laplace
,
model-method-optimize
,
model-method-pathfinder
,
model-method-sample
,
model-method-sample_mpi
,
model-method-variables
,
model-method-variational
## Not run:
# Example of removing unnecessary whitespace
file <- write_stan_file("
data {
int N;
array[N] int y;
}
parameters {
real lambda;
}
model {
target +=
poisson_lpmf(y | lambda);
}
")
# set compile=FALSE then call format to fix old syntax
mod <- cmdstan_model(file, compile = FALSE)
mod$format(canonicalize = list("deprecations"))
# overwrite the original file instead of just printing it
mod$format(canonicalize = list("deprecations"), overwrite_file = TRUE)
mod$compile()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.