diff --git a/.github/prehooks/pre-commit b/.github/prehooks/pre-commit index 6814b90f..76f833ce 100755 --- a/.github/prehooks/pre-commit +++ b/.github/prehooks/pre-commit @@ -33,7 +33,7 @@ echo "Running pre-commit hook..." # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if command -v Rscript > /dev/null; then - if [ "$(Rscript -e 'cat(all(c('"'pkgload'"', '"'devtools'"', '"'dplyr'"', '"'styler'"') %in% rownames(installed.packages())))')" = "TRUE" ]; 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')" currentpkg=`Rscript -e "cat(pkgload::pkg_name())"` echo "-> Adding all files in 'data-raw' to this commit" diff --git a/DESCRIPTION b/DESCRIPTION index a909b844..fcd410fc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.8.2.9077 +Version: 1.8.2.9078 Date: 2023-01-05 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 58d290bc..24ebfaa2 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# 1.8.2.9077 +# AMR 1.8.2.9078 *(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)* diff --git a/R/sysdata.rda b/R/sysdata.rda index 0788095e..e7d3d6f9 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/_pre_commit_hook.R b/data-raw/_pre_commit_hook.R index be217489..de2e808d 100644 --- a/data-raw/_pre_commit_hook.R +++ b/data-raw/_pre_commit_hook.R @@ -486,14 +486,16 @@ suppressMessages(devtools::document(quiet = TRUE)) # Style pkg --------------------------------------------------------------- -# if (interactive()) { -# # only when sourcing this file ourselves -# usethis::ui_info("Styling package") -# styler::style_pkg( -# style = styler::tidyverse_style, -# filetype = c("R", "Rmd") -# ) -# } +if (!"styler" %in% rownames(utils::installed.packages())) { + message("Package 'styler' not installed!") +} else if (interactive()) { + # # only when sourcing this file ourselves + # usethis::ui_info("Styling package") + # styler::style_pkg( + # style = styler::tidyverse_style, + # filetype = c("R", "Rmd") + # ) +} # Finished ---------------------------------------------------------------- diff --git a/man/ab_property.Rd b/man/ab_property.Rd index a94a36f8..7a49e2b6 100644 --- a/man/ab_property.Rd +++ b/man/ab_property.Rd @@ -62,7 +62,7 @@ set_ab_names( \item{tolower}{a \link{logical} to indicate whether the first \link{character} of every output should be transformed to a lower case \link{character}. This will lead to e.g. "polymyxin B" and not "polymyxin b".} -\item{...}{in case of \code{\link[=set_ab_names]{set_ab_names()}} and \code{data} is a \link{data.frame}: variables to select (supports tidy selection such as \code{column1:column4}), otherwise other arguments passed on to \code{\link[=as.ab]{as.ab()}}} +\item{...}{in case of \code{\link[=set_ab_names]{set_ab_names()}} and \code{data} is a \link{data.frame}: columns to select (supports tidy selection such as \code{column1:column4}), otherwise other arguments passed on to \code{\link[=as.ab]{as.ab()}}} \item{only_first}{a \link{logical} to indicate whether only the first ATC code must be returned, with giving preference to J0-codes (i.e., the antimicrobial drug group)} diff --git a/man/custom_eucast_rules.Rd b/man/custom_eucast_rules.Rd index 21ce6c13..55d42503 100644 --- a/man/custom_eucast_rules.Rd +++ b/man/custom_eucast_rules.Rd @@ -60,7 +60,7 @@ eucast_rules(df, rules = "custom", custom_rules = x, info = FALSE) \subsection{Using taxonomic properties in rules}{ -There is one exception in variables used for the rules: all column names of the \link{microorganisms} data set can also be used, but do not have to exist in the data set. These column names are: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence" and "snomed". Thus, this next example will work as well, despite the fact that the \code{df} data set does not contain a column \code{genus}: +There is one exception in columns used for the rules: all column names of the \link{microorganisms} data set can also be used, but do not have to exist in the data set. These column names are: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence" and "snomed". Thus, this next example will work as well, despite the fact that the \code{df} data set does not contain a column \code{genus}: \if{html}{\out{
}}\preformatted{y <- custom_eucast_rules(TZP == "S" & genus == "Klebsiella" ~ aminopenicillins == "S", TZP == "R" & genus == "Klebsiella" ~ aminopenicillins == "R") diff --git a/man/mean_amr_distance.Rd b/man/mean_amr_distance.Rd index 5e6f9429..88e166a5 100644 --- a/man/mean_amr_distance.Rd +++ b/man/mean_amr_distance.Rd @@ -16,7 +16,7 @@ mean_amr_distance(x, ...) amr_distance_from_row(amr_distance, row) } \arguments{ -\item{x}{a vector of class \link[=as.rsi]{rsi}, \link[=as.rsi]{rsi} or \link[=as.rsi]{rsi}, or a \link{data.frame} containing columns of any of these classes} +\item{x}{a vector of class \link[=as.rsi]{rsi}, \link[=as.mic]{mic} or \link[=as.disk]{disk}, or a \link{data.frame} containing columns of any of these classes} \item{...}{variables to select (supports \link[tidyselect:language]{tidyselect language} such as \code{column1:column4} and \code{where(is.mic)}, and can thus also be \link[=ab_selector]{antibiotic selectors}} @@ -30,13 +30,13 @@ amr_distance_from_row(amr_distance, row) Calculates a normalised mean for antimicrobial resistance between multiple observations, to help to identify similar isolates without comparing antibiograms by hand. } \details{ -The mean AMR distance is a normalised numeric value to compare AMR test results and can help to identify similar isolates, without comparing antibiograms by hand. For common numeric data this distance is equal to \href{https://en.wikipedia.org/wiki/Standard_score}{Z scores} (the number of standard deviations from the mean). +The mean AMR distance is effectively \href{https://en.wikipedia.org/wiki/Standard_score}{the Z-score}; a normalised numeric value to compare AMR test results which can help to identify similar isolates, without comparing antibiograms by hand. -MIC values (see \code{\link[=as.mic]{as.mic()}}) are transformed with \code{\link[=log2]{log2()}} first; their distance is calculated as \code{(log2(x) - mean(log2(x))) / sd(log2(x))}. +MIC values (see \code{\link[=as.mic]{as.mic()}}) are transformed with \code{\link[=log2]{log2()}} first; their distance is thus calculated as \code{(log2(x) - mean(log2(x))) / sd(log2(x))}. R/SI values (see \code{\link[=as.rsi]{as.rsi()}}) are transformed using \code{"S"} = 1, \code{"I"} = 2, and \code{"R"} = 3. If \code{combine_SI} is \code{TRUE} (default), the \code{"I"} will be considered to be 1. -For data sets, the mean AMR distance will be calculated per variable, after which the mean of all columns will returned per row (using \code{\link[=rowMeans]{rowMeans()}}), see \emph{Examples}. +For data sets, the mean AMR distance will be calculated per column, after which the mean per row will be returned, see \emph{Examples}. Use \code{\link[=amr_distance_from_row]{amr_distance_from_row()}} to subtract distances from the distance of one row, see \emph{Examples}. } @@ -46,14 +46,24 @@ Isolates with distances less than 0.01 difference from each other should be cons } \examples{ -x <- random_mic(10) -x -mean_amr_distance(x) +rsi <- random_rsi(10) +rsi +mean_amr_distance(rsi) + +mic <- random_mic(10) +mic +mean_amr_distance(mic) +# equal to the Z-score of their log2: +(log2(mic) - mean(log2(mic))) / sd(log2(mic)) + +disk <- random_disk(10) +disk +mean_amr_distance(disk) y <- data.frame( id = LETTERS[1:10], - amox = random_mic(10, ab = "amox", mo = "Escherichia coli"), - cipr = random_mic(10, ab = "cipr", mo = "Escherichia coli"), + amox = random_rsi(10, ab = "amox", mo = "Escherichia coli"), + cipr = random_disk(10, ab = "cipr", mo = "Escherichia coli"), gent = random_mic(10, ab = "gent", mo = "Escherichia coli"), tobr = random_mic(10, ab = "tobr", mo = "Escherichia coli") ) @@ -65,7 +75,7 @@ y[order(y$amr_distance), ] if (require("dplyr")) { y \%>\% mutate( - amr_distance = mean_amr_distance(., where(is.mic)), + amr_distance = mean_amr_distance(y), check_id_C = amr_distance_from_row(amr_distance, id == "C") ) \%>\% arrange(check_id_C) @@ -76,7 +86,7 @@ if (require("dplyr")) { filter(mo_genus() == "Enterococcus" & mo_species() != "") \%>\% select(mo, TCY, carbapenems()) \%>\% group_by(mo) \%>\% - mutate(d = mean_amr_distance(., where(is.rsi))) \%>\% - arrange(mo, d) + mutate(dist = mean_amr_distance(.)) \%>\% + arrange(mo, dist) } }