| Title: | A Mildly Opinionated Stan Bayesian Workflow |
|---|---|
| Description: | Streamlines access to the Stan ecosystem by attaching core workflow packages, surfacing conflicts, and providing helpers to set up Stan interfaces with sensible defaults. Facilitates the Bayesian Workflow as described in Gelman et al. (2020) <https://arxiv.org/abs/2011.01808>. |
| Authors: | Visruth Srimath Kandali [aut, cre, cph] (ORCID: <https://orcid.org/0009-0005-9097-0688>), Jonah Gabry [ctb], Posit Software, PBC [cph] (Copyright holder for code adapted from tidyverse package (MIT); see LICENSE.note) |
| Maintainer: | Visruth Srimath Kandali <[email protected]> |
| License: | BSD_3_clause + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-09-30 13:12:56 UTC |
| Source: | https://github.com/VisruthSK/stanflow |
Print a consolidated status report showing attached packages, available interfaces, and any conflicts.
flow_check(check_updates = FALSE, only = NULL)flow_check(check_updates = FALSE, only = NULL)
check_updates |
If |
only |
Set this to a character vector to restrict to conflicts only between the provided packages and loaded stanflow packages. |
Invisibly returns the character vector that was printed.
flow_check()flow_check()
Configures brms to use available cores and sets the backend.
Prefer setup_interface() for user-facing setup since it performs argument
validation and defaults; setup_brms() assumes inputs are already checked.
setup_brms(quiet, brms_backend, cores, dry_run = FALSE)setup_brms(quiet, brms_backend, cores, dry_run = FALSE)
quiet |
Logical. If |
brms_backend |
Character. The |
cores |
Integer. Number of cores to use. Defaults to
|
dry_run |
Logical. If |
Returns NULL invisibly.
## Not run: setup_brms(quiet = TRUE, brms_backend = "cmdstanr", cores = 2) ## End(Not run)## Not run: setup_brms(quiet = TRUE, brms_backend = "cmdstanr", cores = 2) ## End(Not run)
Checks the C++ toolchain, locates CmdStan, and installs or upgrades
CmdStan if needed. Prefer setup_interface() for user-facing setup since
it performs argument validation and defaults; setup_cmdstanr() assumes
inputs are already checked.
setup_cmdstanr( quiet, force, reinstall = FALSE, check_updates = FALSE, cores, dry_run = FALSE )setup_cmdstanr( quiet, force, reinstall = FALSE, check_updates = FALSE, cores, dry_run = FALSE )
quiet |
Logical. If |
force |
Logical. If |
reinstall |
Logical. If |
check_updates |
Logical. If |
cores |
Integer. Number of cores to use. Defaults to
|
dry_run |
Logical. If |
Returns TRUE invisibly when no install/upgrade is needed.
Otherwise, returns NULL invisibly after installation.
## Not run: setup_cmdstanr( quiet = TRUE, force = TRUE, reinstall = FALSE, check_updates = FALSE, cores = 2 ) ## End(Not run)## Not run: setup_cmdstanr( quiet = TRUE, force = TRUE, reinstall = FALSE, check_updates = FALSE, cores = 2 ) ## End(Not run)
This function ensures specific Stan interfaces are installed, configured, and loaded. It handles package installation (from R-multiverse/CRAN (stable) or Stan universe (dev)) and performs necessary one-time setup (like installing CmdStan).
setup_interface( interface = c("brms", "cmdstanr", "rstan", "rstanarm"), cores = getOption("mc.cores"), quiet = getOption("stanflow.quiet", FALSE), force = FALSE, reinstall = FALSE, check_updates = FALSE, dev = FALSE, brms_backend = c("cmdstanr", "rstan"), rstan_auto_write = TRUE, dry_run = FALSE )setup_interface( interface = c("brms", "cmdstanr", "rstan", "rstanarm"), cores = getOption("mc.cores"), quiet = getOption("stanflow.quiet", FALSE), force = FALSE, reinstall = FALSE, check_updates = FALSE, dev = FALSE, brms_backend = c("cmdstanr", "rstan"), rstan_auto_write = TRUE, dry_run = FALSE )
interface |
A character vector. Select at least one of: "brms", "cmdstanr", "rstan", "rstanarm". |
cores |
Integer. Number of cores to use. Defaults to
|
quiet |
Logical. If |
force |
Logical. If |
reinstall |
Logical. If |
check_updates |
Logical. If |
dev |
Logical. If |
brms_backend |
Character. The |
rstan_auto_write |
Logical. If |
dry_run |
Logical. If |
The setup functions are exported (e.g., setup_brms()) for transparency.
Each function has some side effects, mainly setting mc.cores, see the function
for specifics.
Returns attached package names invisibly. With dry_run = TRUE, returns the package names that would be attached.
## Not run: options(mc.cores = 2) setup_interface("cmdstanr", quiet = TRUE) setup_interface( c("brms", "cmdstanr"), brms_backend = "cmdstanr", quiet = TRUE ) ## End(Not run)## Not run: options(mc.cores = 2) setup_interface("cmdstanr", quiet = TRUE) setup_interface( c("brms", "cmdstanr"), brms_backend = "cmdstanr", quiet = TRUE ) ## End(Not run)
Configures rstan to use available cores and write compiled models to disk.
Prefer setup_interface() for user-facing setup since it performs argument
validation and defaults; setup_rstan() assumes inputs are already checked.
setup_rstan(quiet, cores, rstan_auto_write, dry_run = FALSE)setup_rstan(quiet, cores, rstan_auto_write, dry_run = FALSE)
quiet |
Logical. If |
cores |
Integer. Number of cores to use. Defaults to
|
rstan_auto_write |
Logical. If |
dry_run |
Logical. If |
Returns NULL invisibly.
## Not run: setup_rstan(quiet = TRUE, cores = 2, rstan_auto_write = TRUE) ## End(Not run)## Not run: setup_rstan(quiet = TRUE, cores = 2, rstan_auto_write = TRUE) ## End(Not run)
Configures rstanarm to use available cores.
Prefer setup_interface() for user-facing setup since it performs argument
validation and defaults; setup_rstanarm() assumes inputs are already checked.
setup_rstanarm(quiet, cores, dry_run = FALSE)setup_rstanarm(quiet, cores, dry_run = FALSE)
quiet |
Logical. If |
cores |
Integer. Number of cores to use. Defaults to
|
dry_run |
Logical. If |
Returns NULL invisibly.
## Not run: setup_rstanarm(quiet = TRUE, cores = 2) ## End(Not run)## Not run: setup_rstanarm(quiet = TRUE, cores = 2) ## End(Not run)
stan_cite() finds Stan packages and functions used in a project, then
returns their citations as BibTeX or bibentry records.
stan_cite( path = ".", strict = FALSE, format = c("bibtex", "bibentry"), skip_dirs = ascribe::scan_skip_dirs(), ignore_unqualified_functions = ascribe::stdlib_funs(), use_knitr = FALSE, quiet = getOption("stanflow.quiet", FALSE) )stan_cite( path = ".", strict = FALSE, format = c("bibtex", "bibentry"), skip_dirs = ascribe::scan_skip_dirs(), ignore_unqualified_functions = ascribe::stdlib_funs(), use_knitr = FALSE, quiet = getOption("stanflow.quiet", FALSE) )
path |
A single project directory (searched recursively) or a vector of files (.R/.Rmd/.qmd). |
strict |
If |
format |
One of |
skip_dirs |
Character vector of directory names to skip when scanning a
directory. Defaults to |
ignore_unqualified_functions |
Defaults to exports from base R packages
listed in |
use_knitr |
Logical. If |
quiet |
Logical. If |
A BibTeX character vector or a bibentry object.
path <- tempfile(fileext = ".R") writeLines( c( "# one messy analysis file", "library(posterior)", "requireNamespace(\"loo\")", "draws <- as_draws(list(mu = rnorm(10)))", "posterior::rhat(draws)", "loo::loo(matrix(1))" ), path ) stan_cite(path, quiet = TRUE) stan_cite(path, format = "bibentry", quiet = TRUE) unlink(path)path <- tempfile(fileext = ".R") writeLines( c( "# one messy analysis file", "library(posterior)", "requireNamespace(\"loo\")", "draws <- as_draws(list(mu = rnorm(10)))", "posterior::rhat(draws)", "loo::loo(matrix(1))" ), path ) stan_cite(path, quiet = TRUE) stan_cite(path, format = "bibentry", quiet = TRUE) unlink(path)
Print the Stan ASCII art logo
stan_logo()stan_logo()
Invisibly returns the character vector that was printed.
stan_logo()stan_logo()
Stan package repositories
stan_repos(dev = FALSE)stan_repos(dev = FALSE)
dev |
Include the development r-universe repo–don't use this unless you need the latest commits. |
Character vector of repository URLs.
stan_repos() stan_repos(dev = TRUE)stan_repos() stan_repos(dev = TRUE)
List conflicts between stanflow packages and other attached packages.
stanflow_conflicts(only = NULL) ## S3 method for class 'stanflow_conflicts' print(x, ...)stanflow_conflicts(only = NULL) ## S3 method for class 'stanflow_conflicts' print(x, ...)
only |
Defaults to |
x |
A |
... |
Unused. Included for consistency with |
There are several conflicts that are deliberately ignored: diag,
drop, match, \%in\%, mad, sd, and var from posterior.
Adapted from tidyverse::tidyverse_conflicts() for stanflow's package set.
Invisibly returns x.
stanflow_conflicts() stanflow_conflicts(c("base")) conflicts <- stanflow_conflicts() print(conflicts)stanflow_conflicts() stanflow_conflicts(c("base")) conflicts <- stanflow_conflicts() print(conflicts)
Returns a data frame of Stan workflow packages and their local/remote versions.
When check_updates = FALSE, remote versions are not queried and the remote
and behind columns are NA and FALSE, respectively.
Adapted from tidyverse::tidyverse_deps().
stanflow_deps(recursive = FALSE, dev = FALSE, check_updates = TRUE)stanflow_deps(recursive = FALSE, dev = FALSE, check_updates = TRUE)
recursive |
If |
dev |
If |
check_updates |
Logical. If |
A data frame with columns:
Package name.
Repository version (character, NA when not queried).
Installed version (character, "0" if not installed).
Logical; TRUE when remote is newer than local.
## Not run: # Full dependency check with remote versions stanflow_deps(recursive = TRUE) # Local-only inventory (fast, no network) stanflow_deps(check_updates = FALSE) ## End(Not run)## Not run: # Full dependency check with remote versions stanflow_deps(recursive = TRUE) # Local-only inventory (fast, no network) stanflow_deps(check_updates = FALSE) ## End(Not run)
Adapted from tidyverse::tidyverse_logo().
stanflow_logo()stanflow_logo()
Invisibly returns the character vector that was printed.
stanflow_logo()stanflow_logo()
Checks for outdated Stan workflow packages and installs updates. This function
requires an interactive R session for installation unless dry_run = TRUE.
Dry runs check repositories and preview installs without prompting or
installing packages.
Adapted from tidyverse::tidyverse_update().
stanflow_update(recursive = FALSE, dev = FALSE, dry_run = FALSE)stanflow_update(recursive = FALSE, dev = FALSE, dry_run = FALSE)
recursive |
If |
dev |
If |
dry_run |
Logical. If |
Invisibly returns a data frame of outdated packages (same columns as
stanflow_deps). Returns NULL invisibly when no updates are
needed.
## Not run: # Update direct dependencies only stanflow_update() # Update full dependency tree (including suggests) stanflow_update(recursive = TRUE) ## End(Not run)## Not run: # Update direct dependencies only stanflow_update() # Update full dependency tree (including suggests) stanflow_update(recursive = TRUE) ## End(Not run)