Translate Stan model specification to C++ code
Translate a model specification in Stan code to C++ code, which can then be compiled and loaded for sampling.
stanc(file, model_code = '', model_name = "anon_model", verbose = FALSE, obfuscate_model_name = TRUE, allow_undefined = FALSE, isystem = c(if (!missing(file)) dirname(file), getwd())) stanc_builder(file, isystem = c(dirname(file), getwd()), verbose = FALSE, obfuscate_model_name = FALSE, allow_undefined = FALSE)
file |
A character string or a connection that R supports specifying the Stan model specification in Stan's modeling language. |
model_code |
Either a character string containing a Stan model
specification or the name of a character string object in the workspace.
This parameter is used only if parameter |
model_name |
A character string naming the model. The
default is |
verbose |
Logical, defaulting to |
obfuscate_model_name |
Logical, defaulting to |
isystem |
A character vector naming a path to look for
file paths in |
allow_undefined |
A logical scalar defaulting to |
The stanc_builder
function supports the standard C++ convention of
specifying something like #include "my_includes.txt"
on an entire line
within the file named by the file
argument. In other words,
stanc_builder
would look for "my_includes.txt"
in (or under) the
directories named by the isystem
argument and — if found — insert its
contents verbatim at that position before calling stanc
on the resulting
model_code
. This mechanism reduces the need to copy common chunks of code
across Stan programs. It is possible to include such files recursively.
Note that line numbers referred to in parser warnings or errors refer to the
postprocessed Stan program rather than file
. In the case of a parser
error, the postprocessed Stan program will be printed after the error message.
Line numbers referred to in messages while Stan is executing also refer to
the postprocessed Stan program which can be obtained by calling
get_stancode
.
A list with named entries:
model_name
Character string for the model name.
model_code
Character string for the model's Stan specification.
cppcode
Character string for the model's C++ code.
status
Logical indicating success/failure (always TRUE
)
of translating the Stan code.
Unlike R, in which variable identifiers may contain dots (e.g. a.1
),
Stan prohibits dots from occurring in variable identifiers. Furthermore,
C++ reserved words and Stan reserved words may not be used for variable names;
see the Stan User's Guide for a complete list.
The Stan Development Team Stan Modeling Language User's Guide and Reference Manual. http://mc-stan.org/.
The Stan Development Team CmdStan Interface User's Guide. http://mc-stan.org.
stan_model
and stan
stanmodelcode <- " data { int<lower=0> N; real y[N]; } parameters { real mu; } model { mu ~ normal(0, 10); y ~ normal(mu, 1); } " r <- stanc(model_code = stanmodelcode, model_name = "normal1") str(r)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.