enw_stan_to_r: Expose 'epinowcast' stan functions in R

View source: R/model-tools.R

enw_stan_to_rR Documentation

Expose epinowcast stan functions in R

Description

This function facilitates the exposure of Stan functions from the epinowcast package in R. It utilizes the expose_functions() method of cmdstanr::CmdStanModel or this purpose. This function is useful for developers and contributors to the epinowcast package, as well as for users interested in exploring and prototyping with model functionalities.

Usage

enw_stan_to_r(
  files = list.files(include),
  include = system.file("stan", "functions", package = "epinowcast"),
  global = TRUE,
  verbose = TRUE,
  ...
)

Arguments

files

A character vector specifying the names of Stan files to be exposed. These must be in the include directory. Defaults to all Stan files in the include directory. Note that the following files contain overloaded functions and cannot be exposed: "delay_lpmf.stan", "allocate_observed_obs.stan", "obs_lpmf.stan", and "effects_priors_lp.stan".

include

A character string specifying the directory containing Stan files. Defaults to the 'stan/functions' directory of the epinowcast() package.

global

A logical value indicating whether to expose the functions globally. Defaults to TRUE. Passed to the expose_functions() method of cmdstanr::CmdStanModel.

verbose

Logical, defaults to TRUE. Should verbose messages be shown.

...

Additional arguments passed to enw_model.

Value

An object of class CmdStanModel with functions from the model exposed for use in R.

See Also

Functions used to help convert models into the format required for stan enw_formula_as_data_list(), enw_get_cache(), enw_model(), enw_pathfinder(), enw_priors_as_data_list(), enw_replace_priors(), enw_sample(), enw_set_cache(), enw_unset_cache(), remove_profiling(), write_stan_files_no_profile()

Examples


# Compile functions in stan/functions/hazard.stan
stan_functions <- enw_stan_to_r("hazard.stan")
# These functions can now be used in R
stan_functions$functions$prob_to_hazard(c(0.5, 0.1, 0.1))
# or exposed globally and used directly
prob_to_hazard(c(0.5, 0.1, 0.1))


seabbs/epinowcast documentation built on Aug. 28, 2024, 12:31 p.m.