A template repository for modern R development with renv using R6 classes, validation with checkmate, logging with lgr, argument parsing with optparse, and a Shiny web app interface. Formatted with Air, linted with Jarl, and tested with testthat using GitHub Actions.
- Replace
YOURUSERNAMEandIMAGENAMEin.github/workflows/docker-image.yml[or delete file]. - Replace data in
datawith your own (test) data [or delete if you don't have data]. - Adjust
.gitattributesaccording to your needs [or delete file]. - Adjust
.gitignoreaccording to your needs. - Setup your
CITATION.cffaccording to your needs [or delete file]. - Update attribution in
Dockerfileand write image instructions, see also Docker. - Replace copyright name in
LICENSE. - Update the main script in
lib/main.R. - Delete example
.Rfiles inlib/[and create your own]. - Check if
tests/testthat.Rneeds updating. - Write tests in
tests/testthat/. - Document your code inline using roxygen2 style.
- Document your code/script by writing a documentation page, see Documentation.
- Adjust this
README.mdto your needs!
It's recommended to use rig - the R Installation Manager.
- rig:
- Install a specific R version, e.g.
4.6.1:rig add 4.6.1
- Set a default R version, e.g.
4.6.1:rig default 4.6.1
- Install a specific R version, e.g.
- renv:
- Restore an R environment:
or
Rscript -e "renv::restore()"renv::restore()
- Snapshot an R environment:
or
Rscript -e "renv::snapshot()"renv::snapshot()
- Install a package:
or
Rscript -e "renv::install('pkg')"renv::install("pkg")
- Install a package from Bioconductor:
or
Rscript -e "renv::install('bioc::pkg')"renv::install("bioc::pkg")
- Restore an R environment:
- Air:
- Format files:
air format
- Alternatively, setup
aireditor integration as described here. - Check if files are properly formatted:
air format --check
- Format files:
- Jarl:
- Lint with
jarl:jarl check .
- Lint with
- testthat:
- Test with
testthat:Rscript -e "source('tests/testthat.R')"
- Test with
- Run application:
- CLI mode (example for this application):
Rscript run.R -f data/characters.csv
- Shiny mode (example for this application):
Rscript run.R -s
- CLI mode (example for this application):
This template features inline documentation using roxygen2
syntax. For setting up an online documentation page there is a VitePress
template included in docs. It uses the Catppuccin theme.
- Adjust the
docs/.vitepress/config.mtsfile to your needs. - Update the markdown files in
docs/md/. - The documentation is automatically built via GitHub Actions using this workflow, but you can see a live preview or build it locally by doing the following:
Quarto would be a possible and recommended alternative for building documentation pages. If you write an R package you might also want to consider pkgdown.
If you want to containerize your R project with Docker there are a few things to keep in mind, as pointed out below. You may also find it helpful to read through this renv documentation.
Depending on your R environment you will need to install additional system dependencies in your Docker file. This mostly involves some trial and error but boils down to the following steps:
- Checking the output of renv::sysreqs(),
e.g. using:
renv::sysreqs(distro = "ubuntu:24.04", report = TRUE, collapse = TRUE)
- Checking the output of
renv::restore()on the first image build. - Debugging the build error messages you get.
It's recommended to build the image using a clean repository state, e.g. using:
git clean -f -d -XAlternatively consider using a .dockerignore file.
- Help for this template:
- Contact: micha.birklbauer@gmail.com
Important
The below sections should be adjusted and updated by you!
If you are using PLACEHOLDER please cite:
Very important title
Important Author, and Another Important Author
Journal of Cool Stuff 2023 12 (3), 4567-4589
DOI: 12.3456/cool-stuff