Compile a stan model while pointing at the package default include directory (stan
) for #include statements
Source: R/compile_model.R
compile_model.Rd
This function reads in and optionally compiles a Stan model.
It is written to search the installed package stan
directory
for additional source files to include. Within each stan file,
use #include {path to your file with the stan directory}.stan
Usage
compile_model(
model_filepath = system.file("stan", "wwinference.stan", package = "wwinference"),
include_paths = system.file("stan", package = "wwinference"),
threads = FALSE,
target_dir = tempdir(),
stanc_options = list(),
cpp_options = list(),
verbose = TRUE,
...
)
Arguments
- model_filepath
path to .stan file defining the model, default is `system.file("stan", "wwinference.stan", package = "wwinference")
- include_paths
path(s) to directories to search for files specified in #include statements. Passed to
cmdstanr::cmdstan_model()
. Defaults to thestan
subdirectory of the installedwwinference
package.- threads
Number of threads to use in model compilation, as an integer. Passed to
cmdstanr::cmdstan_model()
. DefaultFALSE
(use single-threaded compilation).- target_dir
Directory in which to save the compiled stan model binary. Passed as the
dir
keyword argument tocmdstanr::cmdstan_model()
. Defaults to a temporary directory for the R session (the output oftempdir()
).- stanc_options
Options for the stan compiler passed to
cmdstanr::cmdstan_model()
, as a list. See that function's documentation for more details. Defaultlist()
(use default options).- cpp_options
Options for the C++ compiler passed to
cmdstanr::cmdstan_model()
, as a list. See that function's documentation for more details. Defaultlist()
(use default options).- verbose
Write detailed output to the terminal while executing the function? Boolean, default
TRUE
.- ...
Additional keyword arguments passed to
cmdstanr::cmdstan_model()
.
Value
The resulting cmdstanr
model object, as the output
of cmdstanr::cmdstan_model()
.
Details
The code for this function has been adapted
from code written (under an MIT license) as part of
the epinowcast
R package.