| Title: | Facilitating the Use of 'Stan' Within Packages |
|---|---|
| Description: | Infrastructure and functions that can be used for integrating 'Stan' (Carpenter et al. (2017) <doi:10.18637/jss.v076.i01>) code into stand alone R packages which in turn use the 'CmdStan' engine which is often accessed through 'CmdStanR'. Details given in Stan Development Team (2025) <https://mc-stan.org/cmdstanr/>. Using 'CmdStanR' and pre-written 'Stan' code can make package installation easy. Using 'staninside' offers a way to cache user-compiled 'Stan' models in user-specified directories reducing the need to recompile the same model multiple times. |
| Authors: | Michael DeWitt [aut, cre] (ORCID: <https://orcid.org/0000-0001-8940-1967>) |
| Maintainer: | Michael DeWitt <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.4 |
| Built: | 2026-05-22 10:30:23 UTC |
| Source: | https://github.com/medewitt/staninside |
This function clears anything that may exist in the Stan Cache. Most Commonly if you are using the CmdStan backend, you'll have items in your cache.
clear_stan_cache(pkgname)clear_stan_cache(pkgname)
pkgname |
a string, the name of the package |
invisible null
This will removed cached models and requires that rappdirs is installed
This function extracts the Stan Code from a Package and then copies it to your user cache locally.
copy_models(pkgname = "staninside", local_location = NULL)copy_models(pkgname = "staninside", local_location = NULL)
pkgname |
a string, the name of the package |
local_location |
a file path representing the desired location of the local copy. If "default" is provided, the function will use the user cache directory for the package. |
file path of newly created files
local_location <- tempdir() copy_models(pkgname = "staninside", local_location = local_location)local_location <- tempdir() copy_models(pkgname = "staninside", local_location = local_location)
This function looks for Stan code within a given R package a returns a list with the Stan code location within the package and the text of the code,
find_stan_code(pkgname = "staninside")find_stan_code(pkgname = "staninside")
pkgname |
a string, the name of the package in which to look for the Stan code. |
a list with the Stan code location within the package and the text of the code,
find_stan_code(pkgname = "staninside")find_stan_code(pkgname = "staninside")
Create directory and helper files for a Stan package using CmdStanR
setup_stan_package(loc = NULL, use_all = TRUE)setup_stan_package(loc = NULL, use_all = TRUE)
loc |
a file.path indicating package root. |
use_all |
a logical indicating if each section of Stan code
should have it's own directory with a default of |
invisible null
# Create Temporary Directory temp_dir <- tempdir() # Now setup the structur setup_stan_package(loc = temp_dir) # Examine output list.files(temp_dir, recursive = TRUE)# Create Temporary Directory temp_dir <- tempdir() # Now setup the structur setup_stan_package(loc = temp_dir) # Examine output list.files(temp_dir, recursive = TRUE)