mirror of
https://github.com/msberends/AMR.git
synced 2026-11-16 06:30:48 +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
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user