Skip to content

Latest commit

 

History

History
98 lines (63 loc) · 2.95 KB

README.md

File metadata and controls

98 lines (63 loc) · 2.95 KB

License: MIT

Disclaimer: This is not a minimal example.

Template for a reproducible R project with Quarto and {targets}

This is an example of a {targets} workflow that runs Bayesian analyses and rendering a manuscript using Quarto. R/functions.R contains some utility functions that are often used in my workflow. ms/manuscript.qmd contains examples of cross-referencing and parameterized texts.

Requirements for running this demo

Option 1: running on local

  • R (>= 4.0.0)

  • Quarto: An open-source scientific and technical publishing system built on Pandoc

  • cmdstan: The shell interface to Stan

  • TinyTeX: A lightweight, cross-platform, portable, and easy-to-maintain LaTeX distribution based on TeX Live

  • renv: A dependency management toolkit for R

Option 2: running on an Apptainer/Singularity container (Linux only)

Usage

Running code on local

To run analysis:

# To install R packages for the first run
# Rscript -e "renv::restore()"

run Rscript

To generate the manuscript:

make

Currently, it is easier to separate Quarto rendering from a {targets} workflow. See Quarto targets - indicate code chunk that causes error #99

Running code in Apptainer (Linux)

To build Apptainer containers:

sudo apptainer build radian.sif radian.def
apptainer exec --env RENV_PATHS_CACHE=/home/${USER}/renv \
	--env RENV_PATHS_PREFIX_AUTO=TRUE \
	radian.sif Rscript -e "renv::restore()"

To run analysis:

apptainer exec --env RENV_PATHS_CACHE=/home/${USER}/renv \
	--env RENV_PATHS_PREFIX_AUTO=TRUE \
	radian.sif Rscript run.R

.Renviron is ignored in git. It is useful to add the following information to .Renviron to use {renv} caches on Linux.

#renv settings
RENV_PATHS_PREFIX_AUTO=TRUE
RENV_PATHS_CACHE=/home/${USER}/renv

Optional

You can also generate Rd files under man/ by running roxygen2::roxygenise().

Links