Skip to contents

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

Examples

if (FALSE) { # interactive()
# 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))
}