Learn R Programming

rstan (version 2.8.0)

stanc: Translate Stan model specification to C++ code

Description

Translate Stan model specification to C++ code, which can then be compiled and loaded for sampling.

Usage

stanc(file, model_code = '', model_name = "anon_model", verbose = FALSE, ...)

Arguments

file
A character string or a connection that Rsupports specifying the Stan model specification in Stan's modeling language.
model_code
A character string either containing a Stan model specification or the name of a character string object in the workspace. This parameter is used only if parameter file is not specified, so it defaults to empty string.
model_name
A character string naming the model. The default is "anon_model". However, the model name would be derived from file or model_code (if model_code is the name of a character string object) if
verbose
TRUE print out more intermediate information during the translation procedure; FALSE otherwise. The default is FALSE.
...
optional parameters including
  1. obfuscate_model_name(logical),TRUEif not specified. IfFALSE, the model name in the generated C++ code would not contain randomly generated character string so

Value

  • A list with named entries:
    1. model_nameCharacter string for the model name.
    2. model_codeCharacter string for the model's Stan specification.
    3. cppcodeCharacter string for the model's C++ code.
    4. statusLogical indicating success/failure (TRUE/FALSE) of translating the Stan code.

References

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.

See Also

stan_model and stan

Examples

Run this code
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") 
names(r)
cat(r$cppcode)

Run the code above in your browser using DataLab