mirror of
https://github.com/msberends/AMR.git
synced 2026-11-15 22:20:47 +01:00
(v3.0.1.9099) Move microorganisms_known_defects.csv out of tests/ to data-raw/microorganisms_files/
- the list of known defects is development data and must not ship with the package - tests read it from the source repository; mo_repository_root() now walks up from the working directory, so the tests also find the repository from an R CMD check directory inside it (GitHub Actions) - the integrity, known-defects and sentinel tests skip when the source repository is not available - CLAUDE.md: on local commits to main, the git hooks set the version number and date Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6ab8ff8c33
commit
1a7f01bfb0
8 files changed
+42
-14
No files matched your search
@@ -167,6 +167,10 @@ Version format: `major.minor.patch.dev` (e.g., `3.0.1.9021`)
|
||||
- Stable CRAN releases drop the dev suffix (e.g., `3.0.1`)
|
||||
- `NEWS.md` uses sections **New**, **Fixes**, **Updates** with GitHub issue references (`#NNN`)
|
||||
|
||||
### Local commits on `main`: never touch the version number
|
||||
|
||||
When committing directly on `main` in a local clone, **never** edit the `Version:` or `Date:` field in `DESCRIPTION`, nor line 1 of `NEWS.md`, and do not add a version prefix to the commit message. The git hooks in `.github/prehooks/` do this on every commit to `main`: `pre-commit` sets the version (commit count since the last tag + 9001) and date in `DESCRIPTION` and line 1 of `NEWS.md`, and `commit-msg` prepends `(vX.Y.Z.9NNN)` to the commit message. Adding NEWS bullets is still allowed. The section below applies only to PRs.
|
||||
|
||||
### Version and date bump required for every PR
|
||||
|
||||
All PRs are **squash-merged**, so each PR lands as exactly **one commit** on the default branch. Version numbers are kept in sync with the cumulative commit count since the last released tag. Therefore **exactly one version bump is allowed per PR**, regardless of how many intermediate commits are made on the branch.
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
Package: AMR
|
||||
Version: 3.0.1.9098
|
||||
Version: 3.0.1.9099
|
||||
Date: 2026-10-03
|
||||
Title: Antimicrobial Resistance Data Analysis
|
||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# AMR 3.0.1.9098
|
||||
# AMR 3.0.1.9099
|
||||
|
||||
Planned as v3.1.0, mid October 2026.
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ code may only get another name (e.g. a corrected spelling) if it is listed in
|
||||
"Needs a human". The build never removes a released taxon: missing ones are restored, except codes it retires in
|
||||
`data-raw/microorganisms_files/mo_code_retirements.csv` (other organisms with the same genus name, or a genus that
|
||||
is now only known in another domain). Every new row in that file needs its own checkbox in the report, and rows
|
||||
marked `NEEDS REVIEW` also under "Needs a human". After the build, `tests/testthat/microorganisms_known_defects.csv` (the known defects of the
|
||||
marked `NEEDS REVIEW` also under "Needs a human". After the build, `data-raw/microorganisms_files/microorganisms_known_defects.csv` (the known defects of the
|
||||
data set before this rebuild) must be emptied: delete the rows that are solved, and the file itself if none
|
||||
are left. Any remaining row must be explained under "Needs a human".
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ the registry that guarantees this.
|
||||
| `build_mo_code_registry.R` | Recreates `mo_code_registry.csv` from the git tags of all releases. Run it after every new release. |
|
||||
| `mo_code_renames.csv` | The only allowed exceptions: registered codes that get another name, because it is the same taxon (e.g. a corrected spelling or a renamed species group). Every row needs `approved_by` and `approved_date`. |
|
||||
| `mo_code_retirements.csv` | Registered codes that are retired on purpose, because their taxon was another organism (e.g. the *Graphium* butterflies, which were wrongly in the Fungi until v3.0.1). Written by the taxonomy build, with the reason; `as.mo()` translates these codes to `NA` with that reason. Every new row must be reviewed in the git diff. |
|
||||
| `microorganisms_known_defects.csv` | Known defects of the `microorganisms` data set on the main branch, so that the unit tests fail on every new defect. This list may only become shorter, and the file must be deleted once it is empty (after the next taxonomy rebuild). The tests that use it only run in the source repository. |
|
||||
|
||||
## Rules
|
||||
|
||||
|
||||
File renamed without changes.
@@ -69,15 +69,37 @@ read_mo_retirements <- function(root = mo_repository_root()) {
|
||||
}
|
||||
utils::read.csv(file, colClasses = "character", na.strings = character(0))
|
||||
}
|
||||
# known defects of the data set on the main branch (see test-data-microorganisms.R), returns an empty data set
|
||||
# if the file is not there, as it must be deleted once no defects are left
|
||||
read_mo_known_defects <- function(root = mo_repository_root()) {
|
||||
file <- file.path(root, "data-raw", "microorganisms_files", "microorganisms_known_defects.csv")
|
||||
if (is.null(root) || !file.exists(file)) {
|
||||
return(data.frame(rule = character(0), record = character(0)))
|
||||
}
|
||||
utils::read.csv(file, colClasses = "character", na.strings = character(0))
|
||||
}
|
||||
# the root of the source repository, found by walking up from the working directory; this works from the root
|
||||
# itself, from tests/testthat, and from an R CMD check directory inside the repository (as on GitHub Actions).
|
||||
# Returns NULL elsewhere, such as for an installed package, since data-raw/ never ships with the package.
|
||||
mo_repository_root <- function() {
|
||||
# works from the root of the repository and from tests/testthat
|
||||
for (path in c(".", "../..", "..")) {
|
||||
if (file.exists(file.path(path, "data-raw", "microorganisms_files", "mo_code_registry.csv"))) {
|
||||
return(normalizePath(path))
|
||||
path <- normalizePath(".", mustWork = FALSE)
|
||||
for (i in seq_len(6)) {
|
||||
if (file.exists(file.path(path, "data-raw", "microorganisms_files", "mo_code_registry.csv")) &&
|
||||
file.exists(file.path(path, "DESCRIPTION")) &&
|
||||
identical(unname(read.dcf(file.path(path, "DESCRIPTION"), fields = "Package")[1, 1]), "AMR")) {
|
||||
return(path)
|
||||
}
|
||||
parent <- dirname(path)
|
||||
if (parent == path) {
|
||||
break
|
||||
}
|
||||
path <- parent
|
||||
}
|
||||
NULL
|
||||
}
|
||||
skip_if_no_mo_repository <- function() {
|
||||
testthat::skip_if(is.null(mo_repository_root()), "Source repository not available (data-raw/ does not ship with the package)")
|
||||
}
|
||||
|
||||
# names without a rank suffix, e.g. "Kapabacteria {class}" and "Nitrospira (class)" are both the class
|
||||
mo_name_without_suffix <- function(x) {
|
||||
|
||||
@@ -32,15 +32,13 @@
|
||||
#
|
||||
# KNOWN DEFECTS: the data set on the main branch of October 2026 contains defects that will be solved by the
|
||||
# next taxonomy rebuild (e.g. Trichophyton as a bacterium, issue #309). These are listed in
|
||||
# microorganisms_known_defects.csv, so that these tests fail on every NEW defect, while the current ones are
|
||||
# visible. This list may only become shorter, and must be empty after the rebuild (then delete the file).
|
||||
# data-raw/microorganisms_files/microorganisms_known_defects.csv, so that these tests fail on every NEW defect,
|
||||
# while the current ones are visible. This list may only become shorter, and must be empty after the rebuild (then
|
||||
# delete the file). As data-raw/ does not ship with the package, the tests that use this list only run in the
|
||||
# source repository.
|
||||
|
||||
known_defects <- function() {
|
||||
file <- test_path("microorganisms_known_defects.csv")
|
||||
if (!file.exists(file)) {
|
||||
return(data.frame(rule = character(0), record = character(0)))
|
||||
}
|
||||
utils::read.csv(file, colClasses = "character", na.strings = character(0))
|
||||
read_mo_known_defects()
|
||||
}
|
||||
new_defects <- function(rule, records) {
|
||||
setdiff(records, known_defects()$record[known_defects()$rule == rule])
|
||||
@@ -97,6 +95,7 @@ sentinel_defects <- function() {
|
||||
|
||||
test_that("microorganisms: integrity rules", {
|
||||
skip_on_cran()
|
||||
skip_if_no_mo_repository()
|
||||
issues <- mo_integrity_issues(microorganisms, registry = read_mo_registry(), renames = read_mo_renames(), retirements = read_mo_retirements())
|
||||
for (rule in names(issues)) {
|
||||
defects <- new_defects(rule, issues[[rule]])
|
||||
@@ -108,6 +107,7 @@ test_that("microorganisms: integrity rules", {
|
||||
|
||||
test_that("microorganisms: known defects are no longer than needed", {
|
||||
skip_on_cran()
|
||||
skip_if_no_mo_repository()
|
||||
# a known defect that is solved must be removed from the list, so that it cannot come back unnoticed
|
||||
kd <- known_defects()
|
||||
skip_if(nrow(kd) == 0)
|
||||
@@ -124,6 +124,7 @@ test_that("microorganisms: known defects are no longer than needed", {
|
||||
|
||||
test_that("microorganisms: sentinel organisms", {
|
||||
skip_on_cran()
|
||||
skip_if_no_mo_repository()
|
||||
defects <- new_defects("sentinel", sentinel_defects())
|
||||
expect_true(length(defects) == 0, info = paste(defects, collapse = "; "))
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user