Skip to content

pythonhealthdatascience/des_rap_book

Repository files navigation

DES RAP Book: Reproducible Discrete-Event Simulation in Python and R

Python R 4.4.1 Code licence Text licence ORCID


Step-by-step guide for building simulation models as part of a reproducible analytical pipeline (RAP). Check it out at: https://pythonhealthdatascience.github.io/des_rap_book/.


View locally

This website is created using Quarto and hosted on GitHub pages. You can view the site locally. With quarto installed, you will need to:

1. Build the python environment

conda env create --file environment.yaml
conda activate des-rap-book

2. Build the R environment

renv::init()
renv::restore()

3. Create the book.

quarto render

Common reticulate error and solution

When rendering a Quarto document containing executable python code with reticulate, you might encounter:

Error in `use_condaenv()`:
! Unable to locate conda environment 'des-rap-book'.
Backtrace:
    ▆
 1. └─reticulate::use_condaenv("des-rap-book", required = TRUE)

This can occur when multiple Conda or Mamba installations exist (e.g. mambgaforge, miniconda3), or if R is using a different search path than the shell. By default, reticulate only looks in one location for environments, which can cause problems when environments are not where reticulate expects.

To fix this, set the RETICULATE_CONDA environment variable to the correct Conda or Mamba executable. To find the path to your executable, run:

conda env list

Look for your environment in the list. For example, if your environment is at /home/amy/mambaforge/envs/des-rap-book, then your Conda executable is likely at /home/amy/mambaforge/bin/conda.

Set the environment variable like so:

export RETICULATE_CONDA=/home/amy/mambaforge/bin/conda

Now render your book:

quarto render

To avoid needing to set RETICULATE_CONDA every time you open a new terminal, add the export command to an .Renviron file in your project directory. This file is not tracked by Git, and is specific to you. Create the file and add:

RETICULATE_CONDA=/home/amy/mambaforge/bin/conda

Citation

To cite this work, see the CITATION.cff file in this repository or use the "Cite this repository" button on GitHub.


Linting

To lint active Python and R code:

bash lint.sh

Note: inactive code (i.e. code that does not get run when building the book) will not be linted - though the R linter will enforce a terminal newline at the end of each .qmd file.


Funding

This project is supported by the Medical Research Council [grant number MR/Z503915/1].

About

Step-by-step guide for building Python and R simulation models as part of a reproducible analytical pipeline (RAP).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published