From 0d8a91db49cb79c71fe1a6b263a0d26496ced98c Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Tue, 23 Apr 2024 10:55:48 +0200 Subject: [PATCH] rename pre-commit hook to pre-commit checks (no-check) --- .github/prehooks/commit-msg | 16 +++++++++------- .github/workflows/check-recent.yaml | 6 +++--- R/aa_globals.R | 2 +- R/aa_helper_functions.R | 2 +- R/ab_selectors.R | 2 +- R/eucast_rules.R | 2 +- R/guess_ab_col.R | 2 +- R/mo.R | 2 +- .../{_pre_commit_hook.R => _pre_commit_checks.R} | 2 +- data-raw/reproduction_of_microorganisms.R | 4 ++-- 10 files changed, 21 insertions(+), 19 deletions(-) rename data-raw/{_pre_commit_hook.R => _pre_commit_checks.R} (99%) diff --git a/.github/prehooks/commit-msg b/.github/prehooks/commit-msg index aae4609c..e03202f4 100755 --- a/.github/prehooks/commit-msg +++ b/.github/prehooks/commit-msg @@ -29,22 +29,24 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -#!/bin/bash +######################################## +# This script runs before every commit # +######################################## -echo "Running commit-msg hook..." - -# check if the commit message contains '(no-check)' or '(no-verify)' +# check the commit message COMMIT_MSG=$(cat "$1") -if [[ "$COMMIT_MSG" =~ \(no-check\)|\(no-verify\) ]]; then - echo "Commit check bypassed by commit message." +if [[ "$COMMIT_MSG" =~ \(no-check\)|\(no-checks\)|\(no-verify\) ]]; then + echo "Not running pre-commit checks; commit message contains '(no-check)', '(no-checks)', or '(no-verify)." exit 0 fi +echo "Running pre-commit checks..." + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if command -v Rscript > /dev/null; then if [ "$(Rscript -e 'cat(all(c('"'pkgload'"', '"'devtools'"', '"'dplyr'"') %in% rownames(installed.packages())))')" = "TRUE" ]; then - Rscript -e "source('data-raw/_pre_commit_hook.R')" + Rscript -e "source('data-raw/_pre_commit_checks.R')" currentpkg=$(Rscript -e "cat(pkgload::pkg_name())") echo "- Adding changed files in ./data-raw and ./man to this commit" git add data-raw/* diff --git a/.github/workflows/check-recent.yaml b/.github/workflows/check-recent.yaml index 09f0b9e2..c102ee6f 100644 --- a/.github/workflows/check-recent.yaml +++ b/.github/workflows/check-recent.yaml @@ -58,9 +58,9 @@ jobs: - {os: ubuntu-latest, r: 'devel', allowfail: false} # current 'release' version, check all major OSes: - - {os: macOS-latest, r: '4.3', allowfail: false} - - {os: windows-latest, r: '4.3', allowfail: false} - - {os: ubuntu-latest, r: '4.3', allowfail: false} + - {os: macOS-latest, r: 'release', allowfail: false} + - {os: windows-latest, r: 'release', allowfail: false} + - {os: ubuntu-latest, r: 'release', allowfail: false} # older versions (see also check-old.yaml for even older versions): - {os: ubuntu-latest, r: '4.2', allowfail: false} diff --git a/R/aa_globals.R b/R/aa_globals.R index cd832ee5..ba55480d 100755 --- a/R/aa_globals.R +++ b/R/aa_globals.R @@ -28,7 +28,7 @@ # ==================================================================== # # add new version numbers here, and add the rules themselves to "data-raw/eucast_rules.tsv" and clinical_breakpoints -# (sourcing "data-raw/_pre_commit_hook.R" will process the TSV file) +# (sourcing "data-raw/_pre_commit_checks.R" will process the TSV file) EUCAST_VERSION_BREAKPOINTS <- list( # "13.0" = list( # version_txt = "v13.0", diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 7f70ec57..28ee1f79 100644 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -689,7 +689,7 @@ create_eucast_ab_documentation <- function() { ab <- character() for (val in x) { if (paste0("AB_", val) %in% ls(envir = asNamespace("AMR"))) { - # antibiotic group names, as defined in data-raw/_pre_commit_hook.R, such as `CARBAPENEMS` + # antibiotic group names, as defined in data-raw/_pre_commit_checks.R, such as `CARBAPENEMS` val <- eval(parse(text = paste0("AB_", val)), envir = asNamespace("AMR")) } else if (val %in% AMR_env$AB_lookup$ab) { # separate drugs, such as `AMX` diff --git a/R/ab_selectors.R b/R/ab_selectors.R index 3a1f66e5..7e8d233a 100755 --- a/R/ab_selectors.R +++ b/R/ab_selectors.R @@ -611,7 +611,7 @@ ab_select_exec <- function(function_name, } else if (isTRUE(function_name == "antimycobacterials")) { abx <- AMR_env$AB_lookup$ab[which(AMR_env$AB_lookup$group == "Antimycobacterials")] } else { - # their upper case equivalent are vectors with class 'ab', created in data-raw/_pre_commit_hook.R + # their upper case equivalent are vectors with class 'ab', created in data-raw/_pre_commit_checks.R # carbapenems() gets its codes from AMR:::AB_CARBAPENEMS abx <- get(paste0("AB_", toupper(function_name)), envir = asNamespace("AMR")) # manually added codes from add_custom_antimicrobials() must also be supported diff --git a/R/eucast_rules.R b/R/eucast_rules.R index 0cd3b776..a9567b4d 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -590,7 +590,7 @@ eucast_rules <- function(x, # this allows: eucast_rules(x, eucast_rules_df = AMR:::EUCAST_RULES_DF %>% filter(is.na(have_these_values))) eucast_rules_df <- list(...)$eucast_rules_df } else { - # otherwise internal data file, created in data-raw/_pre_commit_hook.R + # otherwise internal data file, created in data-raw/_pre_commit_checks.R eucast_rules_df <- EUCAST_RULES_DF } diff --git a/R/guess_ab_col.R b/R/guess_ab_col.R index ea0c4e94..9f4d1f73 100755 --- a/R/guess_ab_col.R +++ b/R/guess_ab_col.R @@ -335,7 +335,7 @@ get_ab_from_namespace <- function(x, cols_ab) { x_new <- character() for (val in x) { if (paste0("AB_", val) %in% ls(envir = asNamespace("AMR"))) { - # antibiotic group names, as defined in data-raw/_pre_commit_hook.R, such as `AB_CARBAPENEMS` + # antibiotic group names, as defined in data-raw/_pre_commit_checks.R, such as `AB_CARBAPENEMS` val <- eval(parse(text = paste0("AB_", val)), envir = asNamespace("AMR")) } else if (val %in% AMR_env$AB_lookup$ab) { # separate drugs, such as `AMX` diff --git a/R/mo.R b/R/mo.R index e840b28e..b41cd1d0 100755 --- a/R/mo.R +++ b/R/mo.R @@ -460,7 +460,7 @@ as.mo <- function(x, } } - # 'MO_CONS' and 'MO_COPS' are 'mo' vectors created in R/_pre_commit_hook.R + # 'MO_CONS' and 'MO_COPS' are 'mo' vectors created in R/_pre_commit_checks.R out[out %in% MO_CONS] <- "B_STPHY_CONS" out[out %in% MO_COPS] <- "B_STPHY_COPS" if (Becker == "all") { diff --git a/data-raw/_pre_commit_hook.R b/data-raw/_pre_commit_checks.R similarity index 99% rename from data-raw/_pre_commit_hook.R rename to data-raw/_pre_commit_checks.R index 33b23981..8b43fc67 100644 --- a/data-raw/_pre_commit_hook.R +++ b/data-raw/_pre_commit_checks.R @@ -28,7 +28,7 @@ # ==================================================================== # # Run this file to update the package using: -# source("data-raw/_pre_commit_hook.R") +# source("data-raw/_pre_commit_checks.R") library(dplyr, warn.conflicts = FALSE) try(detach("package:data.table", unload = TRUE), silent = TRUE) # to prevent like() to precede over AMR::like diff --git a/data-raw/reproduction_of_microorganisms.R b/data-raw/reproduction_of_microorganisms.R index 6b0206e0..86886121 100644 --- a/data-raw/reproduction_of_microorganisms.R +++ b/data-raw/reproduction_of_microorganisms.R @@ -251,7 +251,7 @@ taxonomy_gbif <- taxonomy_gbif.bak %>% kingdom %in% c("Archaea", "Bacteria", "Protozoa") | # include all of these fungal orders order %in% include_fungal_orders | - # and all of these important genera (see "data-raw/_pre_commit_hook.R") + # and all of these important genera (see "data-raw/_pre_commit_checks.R") # (they also contain bacteria and protozoa, but these will get prevalence = 2 later on) genus %in% AMR:::MO_PREVALENT_GENERA ) %>% @@ -1671,7 +1671,7 @@ if (!identical(example_isolates$mo, as.mo(example_isolates$mo, language = NULL)) # load new data sets again devtools::load_all(".") -source("data-raw/_pre_commit_hook.R") +source("data-raw/_pre_commit_checks.R") devtools::load_all(".") if (!identical(intrinsic_resistant$mo, as.mo(intrinsic_resistant$mo, language = NULL))) {