model-method-expose_functions | R Documentation |
The $expose_functions()
method of a CmdStanModel
object
will compile the functions in the Stan program's functions
block and
expose them for use in R. This can also be specified via the
compile_standalone
argument to the $compile()
method.
This method is also available for fitted model objects (CmdStanMCMC
, CmdStanVB
, etc.).
See Examples.
Note: there may be many compiler warnings emitted during compilation but these can be ignored so long as they are warnings and not errors.
expose_functions(global = FALSE, verbose = FALSE)
global |
(logical) Should the functions be added to the Global
Environment? The default is |
verbose |
(logical) Should detailed information about generated code be
printed to the console? Defaults to |
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-format
,
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:
stan_file <- write_stan_file(
"
functions {
real a_plus_b(real a, real b) {
return a + b;
}
}
parameters {
real x;
}
model {
x ~ std_normal();
}
"
)
mod <- cmdstan_model(stan_file)
mod$expose_functions()
mod$functions$a_plus_b(1, 2)
fit <- mod$sample(refresh = 0)
fit$expose_functions() # already compiled because of above but this would compile them otherwise
fit$functions$a_plus_b(1, 2)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.