stan_package_compile {instantiate}R Documentation

Compile the Stan models in an R package.

Description

Compile all Stan models in a directory, usually in a package.

Usage

stan_package_compile(
  models = instantiate::stan_package_model_files(),
  cmdstan_install = Sys.getenv("CMDSTAN_INSTALL", unset = ""),
  verbose = TRUE,
  quiet = FALSE,
  pedantic = FALSE,
  include_paths = NULL,
  user_header = NULL,
  cpp_options = list(),
  stanc_options = list(),
  force_recompile = getOption("cmdstanr_force_recompile", default = FALSE),
  threads = FALSE,
  ...
)

Arguments

models

Character vector of file paths to Stan model source code files. Defaults to the Stan files in ⁠./src/stan/⁠ because all the Stan model files must live in the ⁠src/stan/⁠ folder for an R package built with instantiate.

cmdstan_install

Character of length 1, how to look for an installed copy of CmdStan. See https://wlandau.github.io/instantiate/ for details. Choices:

  1. "" (default): look at the original value that the CMDSTAN_INSTALL environment variable contained when instantiate at the time when it was installed. If it was "implicit" or "fixed", then choose the corresponding option below. Otherwise, default to "implicit".

  2. "implicit": Let the cmdstanr::cmdstan_path() decide where to look for CmdStan. As explained in the cmdstanr documentation, the output of cmdstanr::cmdstan_path() depends on the current value of the CMDSTAN environment variable. The cmdstanr package must be installed. If it is not installed, then stan_cmdstan_path() returns the empty string "".

  3. "fixed": Use the path to CmdStan that was originally contained in Sys.getenv("CMDSTAN") at the time when instantiate was installed.

verbose

Logical of length 1, whether to set the cmdstanr_verbose global option to print more compiler messages than usual.

quiet

Argument to cmdstanr::cmdstan_model() to control compilation.

pedantic

Logical of length 1, whether to activate pedantic mode when compiling the Stan models. See the cmdstanr documentation for details.

include_paths

Argument to cmdstanr::cmdstan_model() to control model compilation.

user_header

Argument to cmdstanr::cmdstan_model() to control model compilation.

cpp_options

Argument to cmdstanr::cmdstan_model() to control model compilation.

stanc_options

Argument to cmdstanr::cmdstan_model() to model control compilation.

force_recompile

Argument to cmdstanr::cmdstan_model() to model control compilation.

threads

Argument to cmdstanr::cmdstan_model() to model control compilation.

...

Other named arguments to cmdstanr::cmdstan_model().

Details

If building a package using instantiate, all Stan model files must live in a folder called ⁠src/stan/⁠ in the package source directory.

Value

NULL (invisibly). Called for its side effects.

See Also

Other packages: stan_cmdstan_path(), stan_package_clean(), stan_package_configure(), stan_package_model_files()

Examples

if (identical(Sys.getenv("INSTANTIATE_EXAMPLES"), "true")) {
path <- tempfile()
stan_package_create(path = path)
stan_package_configure(path = path)
models <- stan_package_model_files(path)
list.files(file.path(path, "inst", "stan"))
stan_package_compile(models)
list.files(file.path(path, "inst", "stan"))
}

[Package instantiate version 0.2.2 Index]