Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
^\.github$
^README\.md$
^WARP\.md$
Expand All @@ -25,3 +24,8 @@
^_pkgdown\.yml$
^pkgdown-site$
^pkgdown$
^webr$
^codemeta\.json$
^CONTRIBUTING\.md$
^ropensci-readiness\.md$
^tests/js$
79 changes: 79 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Runs R CMD check, tests included, on Linux (release, devel, oldrel-1), macOS
# and Windows for every push to the main branch and every pull request.
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
# The tests that talk to live services (FishBase, GBIF, Global Names) and
# the ones that build a real vision model are guarded by skip_on_cran().
# setup-r would set NOT_CRAN=true; keeping it false here makes those tests
# skip, so a slow or changed web service cannot fail the build. The tests
# that need Python (torch, open_clip) also skip because neither
# RETICULATE_PYTHON nor DIMOOSE_CLIP_WEIGHTS is set. Everything else,
# including the parsers and the vision code against a fake model, runs.
NOT_CRAN: false

steps:
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

# The behaviour tests of the interactive page (tests/js, run from
# tests/testthat/test-wizard-js.R) need node and the jsdom package; they
# skip without them. One job is enough, so only Ubuntu release gets them.
# jsdom is installed outside the checkout so that it cannot end up in
# the package.
- uses: actions/setup-node@v7
if: matrix.config.os == 'ubuntu-latest' && matrix.config.r == 'release'
with:
node-version: 'lts/*'

- name: Install jsdom for the wizard tests
if: matrix.config.os == 'ubuntu-latest' && matrix.config.r == 'release'
run: |
mkdir -p "$RUNNER_TEMP/dimoose-jsdom"
cd "$RUNNER_TEMP/dimoose-jsdom"
npm install --no-audit --no-fund jsdom
echo "DIMOOSE_JSDOM=$RUNNER_TEMP/dimoose-jsdom/node_modules" >> "$GITHUB_ENV"
shell: bash

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
6 changes: 6 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ jobs:
file.create("pkgdown-site/.nojekyll")
shell: Rscript {0}

# The page for people who do not use R: upload a spreadsheet, get the
# wizard. R runs in the browser (webR); build.R bundles the R code the page
# needs and checks it on the Montana key. Served at .../dimoose/webr/
- name: Add the spreadsheet-to-wizard page
run: Rscript webr/build.R pkgdown-site/webr

- name: Deploy to GitHub pages
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Measures test coverage with covr and uploads it to Codecov. Uploads from
# pushes need the repository secret CODECOV_TOKEN (from codecov.io); without
# it the upload step fails on pushes and is skipped quietly on pull requests.
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: test-coverage

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
# As in R-CMD-check.yaml: skip the tests that need live web services
NOT_CRAN: false

steps:
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print(cov)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
files: ./cobertura.xml
plugins: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v7
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ WARP.md

# pkgdown website (built by .github/workflows/pkgdown.yaml)
pkgdown-site/

# The browser page built by webr/build.R (published by the pkgdown workflow)
webr/_site/
24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

125 changes: 125 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Contributing to dimoose

Thank you for helping. Bug reports, keys that fail to import, ideas and pull
requests are all welcome.

## Reporting a problem

Open an issue at <https://github.com/leipzig/dimoose/issues>. It helps to include:

- what you ran, as a small example that can be pasted into R. For a key, the
lead table (`key$leads`) or the spreadsheet rows are usually enough;
- what you expected and what happened instead, with the full error message;
- the output of `sessionInfo()`.

For a FishBase key that imports wrongly, give its key number
(`importFishbase(<number>)`).

Please do not post photos or data you are not allowed to share.

## Proposing a change

For anything larger than a small fix, open an issue first so we can agree on
the approach before you spend time on it.

1. Fork the repository and make a branch from `master`.
2. Install the development dependencies:

```r
install.packages(c("remotes", "devtools"))
remotes::install_deps(dependencies = TRUE)
```

3. Make the change, with a test and documentation (see below).
4. Run the checks:

```r
devtools::document() # regenerates man/ and NAMESPACE from the roxygen comments
devtools::test()
devtools::check()
```

5. Add a line to the top of `NEWS.md` saying what changed, in words a user
of the package would recognise.
6. Open a pull request. The checks run on Linux, macOS and Windows
(`.github/workflows/R-CMD-check.yaml`).

## Code style

- Base R where it is enough; a new dependency needs a good reason. Packages
that only one feature needs go in `Suggests` and are checked for with
`requireNamespace()`, with a message saying what to install.
- Function and argument names are camelCase (`keyFromSpreadsheet()`,
`exportWizard()`), to match the existing interface.
- Call other packages as `pkg::fun()`.
- Error messages say what is wrong and what to do about it, in plain words,
and name the row or lead when there is one
(`"Row 4 has neither `Goes to` nor `Species`"`). Use `stop(..., call. = FALSE)`,
`warning()` and `message()`, not `cat()` or `print()`, outside print methods.
- Comments explain why, not what.

## Documentation

Documentation is written as roxygen2 comments with Markdown, above each
function in `R/`. Do not edit `man/` or `NAMESPACE` by hand. Every exported
function needs a description of what it returns (`@return`) and an example
that runs without the network or optional software; wrap the ones that
cannot in `\dontrun{}` or use `@examplesIf`.

The website (<https://leipzig.github.io/dimoose/>) is built from the
repository by `.github/workflows/pkgdown.yaml`; `_pkgdown.yml` lists the
reference sections, so a new exported function has to be added there.

## Tests

Tests use testthat (3rd edition) and live in `tests/testthat/`.

- Tests must pass with no internet connection and without Python. Logic that
handles downloaded data is tested on saved pages or injected data (see
`test-parse-fishbase.R` and `fakeVisionModel()` in `helper-fake-vision.R`).
- A test that really calls a web service starts with `skip_on_cran()` and
`skip_if_unreachable(url)` (`helper-network.R`). These are skipped on GitHub
Actions, which sets `NOT_CRAN=false`; run them yourself before changing
import code:

```r
Sys.setenv(NOT_CRAN = "true")
devtools::test(filter = "fishbase|names")
```

- A test that needs an optional package starts with
`skip_if_not_installed()`.
- The tests of the real vision model run only when `DIMOOSE_CLIP_WEIGHTS`
points to a weights file (see `test-vision-python.R`).

## The page for people who do not use R

`webr/` holds a static page that runs the spreadsheet-to-wizard path in the
browser with [webR](https://docs.r-wasm.org/webr/latest/). Build and try it with:

```sh
Rscript webr/build.R # writes webr/_site and checks it on the Montana key
python3 -m http.server --directory webr/_site 8000
```

The page loads only the R files listed in `webr/build.R`. If you change
`keyFromSpreadsheet()`, `exportWizard()` or what they call, run the build
again: it fails if those files have come to need code from another file or
another package.

## Data and photos

Third-party data and photos need a licence that allows redistribution, and an
entry in `inst/COPYRIGHTS` (and in `photos.tsv` for the Montana photos) giving
the source, author and licence.

## Conduct

Be kind and assume good faith. Harassment and personal attacks are not
accepted in issues, pull requests or any other project space; report problems
to the maintainer (address in `DESCRIPTION`).

## Licence

By contributing you agree that your contribution is distributed under the
package's licence (GPL; see `DESCRIPTION`).
8 changes: 3 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: dimoose
Type: Package
Title: Tools to Reshape and Manipulate Dichotomous Keys Used in Taxonomic
Identification
Version: 0.2.0
Version: 0.3.0
Authors@R:
person("Jeremy", "Leipzig", , "leipzig@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-7224-9620"))
Expand All @@ -13,7 +13,7 @@ Description: Transforms between dichotomous identification keys and a
and includes PhyloTree Build 17, the human mitochondrial DNA phylogeny
(van Oven 2015, <doi:10.1016/j.fsigss.2015.09.155>), as distributed by
'Haplogrep' 3.
License: GPL
License: GPL (>= 3)
Copyright: See inst/COPYRIGHTS for third-party data and example pages.
URL: https://leipzig.github.io/dimoose/, https://github.com/leipzig/dimoose
BugReports: https://github.com/leipzig/dimoose/issues
Expand All @@ -29,21 +29,19 @@ Imports:
rpart,
rvest (>= 1.0.0),
stats,
tools,
utils,
withr,
xml2
Suggests:
ape,
phangorn,
gbm,
glmertree,
igraph,
jpeg,
jsonlite,
knitr,
lme4,
magick,
partykit,
png,
randomForest,
reticulate (>= 1.41.0),
Expand Down
Loading
Loading