Skip to content

Commit 0f41369

Browse files
authored
Merge pull request #3 from macromeer/update-ggplot2-4
Add tests and CI; move data into data/ and images/
2 parents 515e7bb + c12ac6e commit 0f41369

31 files changed

Lines changed: 2396 additions & 32 deletions

‎.github/workflows/tests.yaml‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
tests:
14+
runs-on: ubuntu-latest
15+
env:
16+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
17+
18+
steps:
19+
- uses: actions/checkout@v7
20+
21+
# Liberation Sans stands in for Arial; pdffonts checks the fonts embedded in the PDF
22+
- name: Install fonts and poppler-utils
23+
run: sudo apt-get update && sudo apt-get install -y fonts-liberation poppler-utils
24+
25+
- uses: r-lib/actions/setup-r@v2
26+
with:
27+
use-public-rspm: true
28+
29+
# Installs the packages listed in DESCRIPTION, including system libraries (ImageMagick)
30+
- uses: r-lib/actions/setup-r-dependencies@v2
31+
with:
32+
dependencies: '"all"'
33+
34+
- name: Run tests
35+
run: Rscript -e 'testthat::test_dir("tests/testthat")'
36+
37+
- name: Upload snapshot differences
38+
if: failure()
39+
uses: actions/upload-artifact@v7
40+
with:
41+
name: snapshot-differences
42+
path: tests/testthat/_snaps/**/*.new.svg
43+
if-no-files-found: ignore

‎DESCRIPTION‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Package: scifigexamples
2+
Title: Scientific Publication Figure Plotting Examples with R
3+
Version: 0.1.0
4+
Description: Example script for a multi-panel scientific figure. This is not
5+
an R package: the file only lists the dependencies, so they can be
6+
installed with pak::local_install_deps() and in CI.
7+
License: GPL-3
8+
Encoding: UTF-8
9+
Depends:
10+
R (>= 4.1)
11+
Imports:
12+
ggforce,
13+
ggplot2 (>= 3.5.0),
14+
grid,
15+
latex2exp,
16+
magick,
17+
patchwork,
18+
scales,
19+
svglite,
20+
systemfonts
21+
Suggests:
22+
testthat (>= 3.0.0),
23+
vdiffr,
24+
withr
25+
Config/testthat/edition: 3

‎README.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,30 @@ Rscript figure_example.R
1818
```
1919

2020
This writes `figure_example.png`, `figure_example.svg` and `figure_example.pdf`.
21+
22+
## Layout
23+
24+
| Path | Contents |
25+
|---|---|
26+
| `figure_example.R` | Script that builds and saves the figure |
27+
| `data/` | CSV data for panels B–F |
28+
| `images/` | Microscopy images for panel A |
29+
| `tests/` | Tests (see below) |
30+
31+
## Tests
32+
33+
The tests check the data loading, that every panel renders without warnings, the exported files, and how each panel looks (visual snapshots with vdiffr). They run on GitHub Actions for every push and pull request. To run them locally:
34+
35+
```r
36+
install.packages(c("testthat", "vdiffr", "withr"))
37+
```
38+
39+
```sh
40+
Rscript -e 'testthat::test_dir("tests/testthat")'
41+
```
42+
43+
If you change a panel on purpose, the snapshot test for it fails. Review the new version and accept it with:
44+
45+
```r
46+
testthat::snapshot_review("snapshots", path = "tests/testthat")
47+
```
File renamed without changes.

0 commit comments

Comments
 (0)