Add Stan infrastructure to an existing R package. To create a new package
containing Stan programs use
use_rstan(pkgdir = ".", license = TRUE, auto_config = TRUE)
Path to package root folder.
Logical or character; whether or not to paste the contents of
license.stan file at the top of all Stan code, or path to such a
TRUE (the default) adds the
GPL (>= 3) license (see
Whether to automatically configure Stan functionality
whenever the package gets installed (see Details). Defaults to
FALSE indicating whether or not any files or
folders where created or modified.
Prepares a package to compile and use Stan code by performing the following steps:
inst/stan folder where all
.stan files defining
Stan models should be stored.
inst/stan/include where optional
license.stan file is stored.
inst/include/stan_meta_header.hpp to include optional header
files used by Stan code.
src folder (if it doesn't exist) to contain the Stan C++ code.
R folder (if it doesn't exist) to contain wrapper code to expose
Stan C++ classes to R.
DESCRIPTION file to contain all needed dependencies to compile
Stan C++ code.
NAMESPACE file is generic (i.e., created by
useDynLib directives. If
NAMESPACE is not generic, display message
telling user what to add to
NAMESPACE for themselves.
auto_config = TRUE, a
configure[.win] file is added to the
rstan_config() whenever the package is installed.
Consequently, the package must list rstantools in the
Imports field for this mechanism to work. Setting
auto_config = FALSE
removes the package's dependency on rstantools, but the package then
must be manually configured by running
stanmodel files in
inst/stan are added, removed, or modified.
stanmodel objects corresponding to the Stan programs included with your
package are stored in a list called
stanmodels. To run one of the Stan
programs from within an R function in your package just pass the
appropriate element of the
stanmodels list to one of the rstan
functions for model fitting (e.g.,
sampling()). For example, for a Stan
"foo.stan" you would use