{"id":14068009,"url":"https://github.com/ropensci/stantargets","last_synced_at":"2025-12-27T10:54:47.786Z","repository":{"id":39569360,"uuid":"315447649","full_name":"ropensci/stantargets","owner":"ropensci","description":"Reproducible Bayesian data analysis pipelines with targets and cmdstanr","archived":false,"fork":false,"pushed_at":"2025-02-07T17:50:07.000Z","size":1744,"stargazers_count":49,"open_issues_count":3,"forks_count":10,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-27T01:04:10.382Z","etag":null,"topics":["bayesian","high-performance-computing","make","r","r-targetopia","reproducibility","rstats","rstats-package","stan","statistics","targets"],"latest_commit_sha":null,"homepage":"https://docs.ropensci.org/stantargets","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ropensci.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null}},"created_at":"2020-11-23T21:41:44.000Z","updated_at":"2025-04-02T02:30:54.000Z","dependencies_parsed_at":"2024-08-13T07:13:42.152Z","dependency_job_id":"1c1dcdf5-a85a-41b6-8222-e520b2ba39a1","html_url":"https://github.com/ropensci/stantargets","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/ropensci/stantargets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstantargets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstantargets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstantargets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstantargets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ropensci","download_url":"https://codeload.github.com/ropensci/stantargets/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstantargets/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264173876,"owners_count":23568109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian","high-performance-computing","make","r","r-targetopia","reproducibility","rstats","rstats-package","stan","statistics","targets"],"created_at":"2024-08-13T07:05:53.701Z","updated_at":"2025-12-27T10:54:47.772Z","avatar_url":"https://github.com/ropensci.png","language":"R","readme":"---\noutput: github_document\n---\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# stantargets \u003cimg src='man/figures/logo.png' align=\"right\" height=\"139\"/\u003e\n\n[![ropensci](https://badges.ropensci.org/430_status.svg)](https://github.com/ropensci/software-review/issues/430)\n[![joss](https://joss.theoj.org/papers/10.21105/joss.03193/status.svg)](https://doi.org/10.21105/joss.03193)\n[![zenodo](https://zenodo.org/badge/315447649.svg)](https://zenodo.org/badge/latestdoi/315447649)\n[![R Targetopia](https://img.shields.io/badge/R_Targetopia-member-blue?style=flat\u0026labelColor=gray)](https://wlandau.github.io/targetopia/)\n\u003c!--\n[![cran](http://www.r-pkg.org/badges/version/stantargets)](https://cran.r-project.org/package=stantargets)\n--\u003e\n[![active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![check](https://github.com/ropensci/stantargets/workflows/check/badge.svg)](https://github.com/ropensci/stantargets/actions?query=workflow%3Acheck)\n[![codecov](https://codecov.io/gh/ropensci/stantargets/branch/main/graph/badge.svg?token=3T5DlLwUVl)](https://app.codecov.io/gh/ropensci/stantargets)\n[![lint](https://github.com/ropensci/stantargets/workflows/lint/badge.svg)](https://github.com/ropensci/stantargets/actions?query=workflow%3Alint)\n\n\nBayesian data analysis usually incurs long runtimes and cumbersome custom code, and the process of prototyping and deploying custom [Stan](https://mc-stan.org) models can become a daunting software engineering challenge. To ease this burden, the `stantargets` R package creates [Stan](https://mc-stan.org) pipelines that are concise, efficient, scalable, and tailored to the needs of Bayesian statisticians. Leveraging [`targets`](https://docs.ropensci.org/targets/), `stantargets` pipelines automatically parallelize the computation and skip expensive steps when the results are already up to date. Minimal custom user-side code is required, and there is no need to manually configure branching, so `stantargets` is easier to use than [`targets`](https://docs.ropensci.org/targets/) and [`CmdStanR`](https://mc-stan.org/cmdstanr/) directly. `stantargets` can access all of [`cmdstanr`](https://github.com/stan-dev/cmdstanr)'s major algorithms (MCMC, variational Bayes, and optimization) and it supports both single-fit workflows and multi-rep simulation studies.\n\n## Prerequisites\n\n1. The [prerequisites of the `targets` R package](https://docs.ropensci.org/targets/index.html#prerequisites).\n1. Basic familiarity with [`targets`](https://docs.ropensci.org/targets/): watch minutes 7 through 40 of [this video](https://youtu.be/Gqn7Xn4d5NI?t=439), then read [this chapter](https://books.ropensci.org/targets/walkthrough.html) of the [user manual](https://books.ropensci.org/targets/).\n1. Familiarity with Bayesian Statistics and [Stan](https://mc-stan.org/). Prior knowledge of [`cmdstanr`](https://mc-stan.org/cmdstanr/) helps.\n\n## How to get started\n\nRead the `stantargets` [introduction](https://docs.ropensci.org/stantargets/articles/introduction.html) and [simulation](https://docs.ropensci.org/stantargets/articles/simulation.html) vignettes, and use \u003chttps://docs.ropensci.org/stantargets/\u003e as a reference while constructing your own workflows. Visit \u003chttps://github.com/wlandau/stantargets-example-validation\u003e for an example project based on the [simulation vignette](https://docs.ropensci.org/stantargets/articles/simulation.html). The example has an [RStudio Cloud workspace](https://rstudio.cloud/project/2466069) which allows you to run the project in a web browser.\n\n## Example projects\n\nDescription | Link\n---|---\nValidating a minimal Stan model | \u003chttps://github.com/wlandau/targets-stan\u003e\nUsing Target Markdown and `stantargets` to validate a Bayesian longitudinal model for clinical trial data analysis | \u003chttps://github.com/wlandau/rmedicine2021-pipeline\u003e\n\n## Installation\n\nInstall the GitHub development version to access the latest features and patches.\n\n```{r, eval = FALSE}\nremotes::install_github(\"ropensci/stantargets\")\n```\n\nThe [CmdStan](https://github.com/stan-dev/cmdstan) command line interface is also required.\n\n```{r, eval = FALSE}\ncmdstanr::install_cmdstan()\n```\n\nIf you have problems installing [CmdStan](https://github.com/stan-dev/cmdstan), please consult the [installation guide of `cmdstanr`](https://mc-stan.org/cmdstanr/articles/cmdstanr.html) and the [installation guide of CmdStan](https://mc-stan.org/docs/2_26/cmdstan-guide/cmdstan-installation.html). Alternatively, the [Stan discourse](https://discourse.mc-stan.org) is a friendly place to ask Stan experts for help.\n\n## Usage\n\nFirst, write a [`_targets.R` file](https://books.ropensci.org/targets/walkthrough.html) that loads your packages, defines a function to generate [Stan](https://mc-stan.org/) data, and lists a pipeline of targets. The target list can call target factories like [`tar_stan_mcmc()`](https://docs.ropensci.org/stantargets/reference/tar_stan_mcmc.html) as well as ordinary targets with [`tar_target()`](https://docs.ropensci.org/targets/reference/tar_target.html). The following minimal example is simple enough to contain entirely within the `_targets.R` file, but for larger projects, you may wish to store functions in separate files as in the [`targets-stan`](https://github.com/wlandau/targets-stan) example.\n\n```{r, eval = FALSE}\n# _targets.R\nlibrary(targets)\nlibrary(stantargets)\n\ngenerate_data \u003c- function(n = 10) {\n  true_beta \u003c- stats::rnorm(n = 1, mean = 0, sd = 1)\n  x \u003c- seq(from = -1, to = 1, length.out = n)\n  y \u003c- stats::rnorm(n, x * true_beta, 1)\n  list(n = n, x = x, y = y, true_beta = true_beta)\n}\n\nlist(\n  tar_stan_mcmc(\n    name = example,\n    stan_files = \"x.stan\",\n    data = generate_data()\n  )\n)\n```\n\nRun [`tar_visnetwork()`](https://docs.ropensci.org/targets/reference/tar_visnetwork.html) to check `_targets.R` for correctness, then call [`tar_make()`](https://docs.ropensci.org/targets/reference/tar_make.html) to run the pipeline. Access the results using [`tar_read()`](https://docs.ropensci.org/targets/reference/tar_read.html), e.g. `tar_read(example_summary_x)`. Visit the [introductory vignette](https://docs.ropensci.org/stantargets/articles/introduction.html) to read more about this example.\n\n## How it works behind the scenes\n\n`stantargets` supports specialized [target factories](https://ropensci.org/blog/2021/02/03/targets/#target-factories) that create ensembles of [target objects](https://docs.ropensci.org/targets/reference/tar_target.html) for [`cmdstanr`](https://github.com/stan-dev/cmdstanr) workflows. These [target factories](https://ropensci.org/blog/2021/02/03/targets/#target-factories) abstract away the details of [`targets`](https://docs.ropensci.org/targets/) and [`cmdstanr`](https://github.com/stan-dev/cmdstanr) and make both packages easier to use. For details, please read the [introductory vignette](https://docs.ropensci.org/stantargets/articles/introduction.html).\n\n## Help\n\nPlease first read the [help guide](https://books.ropensci.org/targets/help.html) to learn how best to ask for help.\n\nIf you have trouble using `stantargets`, you can ask for help in the [GitHub discussions forum](https://github.com/ropensci/stantargets/discussions/categories/help). Because the purpose of `stantargets` is to combine [`targets`](https://docs.ropensci.org/targets/) and [`cmdstanr`](https://github.com/stan-dev/cmdstanr), your issue may have something to do with one of the latter two packages, a [dependency of `targets`](https://github.com/ropensci/targets/blob/4e3ef2a6c986f558a25e544416f480fc01236b6b/DESCRIPTION#L49-L88), or [Stan](https://mc-stan.org) itself. When you troubleshoot, peel back as many layers as possible to isolate the problem. For example, if the issue comes from [`cmdstanr`](https://github.com/stan-dev/cmdstanr), create a [reproducible example](https://reprex.tidyverse.org) that directly invokes [`cmdstanr`](https://github.com/stan-dev/cmdstanr) without invoking `stantargets`. The GitHub discussion and issue forums of those packages, as well as the [Stan discourse](https://discourse.mc-stan.org), are great resources.\n\n## Participation\n\nDevelopment is a community effort, and we welcome discussion and contribution. Please note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms.\n\n## Citation\n\n```{r, warning = FALSE}\ncitation(\"stantargets\")\n```\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fstantargets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropensci%2Fstantargets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fstantargets/lists"}