Compare commits

..

No commits in common. "c7bfc475027f76b56707f202798b9dc36ef0578d" and "fda9c15420d12ef95862b5fb8ac888b7accba859" have entirely different histories.

7 changed files with 70 additions and 49 deletions

View File

@ -12,7 +12,6 @@ This version will eventually become v2.0! We're happy to reach a new major miles
* The MO matching score algorithm (`mo_matching_score()`) now counts deletions and substitutions as 2 instead of 1, which impacts the outcome of `as.mo()` and any `mo_*()` function * The MO matching score algorithm (`mo_matching_score()`) now counts deletions and substitutions as 2 instead of 1, which impacts the outcome of `as.mo()` and any `mo_*()` function
* **Argument `combine_IR` has been removed** from this package (affecting functions `count_df()`, `proportion_df()`, and `rsi_df()` and some plotting functions), since it was replaced with `combine_SI` three years ago * **Argument `combine_IR` has been removed** from this package (affecting functions `count_df()`, `proportion_df()`, and `rsi_df()` and some plotting functions), since it was replaced with `combine_SI` three years ago
* Interpretation **guidelines older than 10 years were removed**, the oldest now included guidelines of EUCAST and CLSI are from 2013 * Interpretation **guidelines older than 10 years were removed**, the oldest now included guidelines of EUCAST and CLSI are from 2013
* Using `units` in `ab_ddd(..., units = "...")` had been deprecated and is now not supported anymore. Use `ab_ddd_units()` instead.
### New ### New
* **EUCAST 2022 and CLSI 2022 guidelines** have been added for `as.rsi()`. EUCAST 2022 is now the new default guideline for all MIC and disks diffusion interpretations. * **EUCAST 2022 and CLSI 2022 guidelines** have been added for `as.rsi()`. EUCAST 2022 is now the new default guideline for all MIC and disks diffusion interpretations.

View File

@ -241,7 +241,20 @@ ab_ddd <- function(x, administration = "oral", ...) {
meet_criteria(administration, is_in = c("oral", "iv"), has_length = 1) meet_criteria(administration, is_in = c("oral", "iv"), has_length = 1)
x <- as.ab(x, ...) x <- as.ab(x, ...)
ddd_prop <- paste0(administration, "_ddd") ddd_prop <- administration
# old behaviour
units <- list(...)$units
if (!is.null(units) && isTRUE(units)) {
if (message_not_thrown_before("ab_ddd", entire_session = TRUE)) {
warning_(
"in `ab_ddd()`: using `ab_ddd(..., units = TRUE)` is deprecated, use `ab_ddd_units()` to retrieve units instead.",
"This warning will be shown once per session."
)
}
ddd_prop <- paste0(ddd_prop, "_units")
} else {
ddd_prop <- paste0(ddd_prop, "_ddd")
}
out <- ab_validate(x = x, property = ddd_prop) out <- ab_validate(x = x, property = ddd_prop)
if (any(ab_name(x, language = NULL) %like% "/" & is.na(out))) { if (any(ab_name(x, language = NULL) %like% "/" & is.na(out))) {
@ -261,17 +274,16 @@ ab_ddd_units <- function(x, administration = "oral", ...) {
meet_criteria(administration, is_in = c("oral", "iv"), has_length = 1) meet_criteria(administration, is_in = c("oral", "iv"), has_length = 1)
x <- as.ab(x, ...) x <- as.ab(x, ...)
ddd_prop <- paste0(administration, "_units") if (any(ab_name(x, language = NULL) %like% "/")) {
out <- ab_validate(x = x, property = ddd_prop)
if (any(ab_name(x, language = NULL) %like% "/" & is.na(out))) {
warning_( warning_(
"in `ab_ddd_units()`: DDDs of some combined products are available for different dose combinations and not (yet) part of the AMR package.", "in `ab_ddd_units()`: DDDs of combined products are available for different dose combinations and not (yet) part of the AMR package.",
"Please refer to the WHOCC website:\n", "Please refer to the WHOCC website:\n",
"www.whocc.no/ddd/list_of_ddds_combined_products/" "www.whocc.no/ddd/list_of_ddds_combined_products/"
) )
} }
out
ddd_prop <- paste0(administration, "_units")
ab_validate(x = x, property = ddd_prop)
} }
#' @rdname ab_property #' @rdname ab_property

7
R/av.R
View File

@ -506,7 +506,6 @@ is.av <- function(x) {
# will be exported using s3_register() in R/zzz.R # will be exported using s3_register() in R/zzz.R
pillar_shaft.av <- function(x, ...) { pillar_shaft.av <- function(x, ...) {
out <- trimws(format(x)) out <- trimws(format(x))
out[!is.na(x)] <- gsub("+", font_subtle("+"), out[!is.na(x)], fixed = TRUE)
out[is.na(x)] <- font_na(NA) out[is.na(x)] <- font_na(NA)
create_pillar_column(out, align = "left", min_width = 4) create_pillar_column(out, align = "left", min_width = 4)
} }
@ -557,7 +556,7 @@ as.data.frame.av <- function(x, ...) {
"[<-.av" <- function(i, j, ..., value) { "[<-.av" <- function(i, j, ..., value) {
y <- NextMethod() y <- NextMethod()
attributes(y) <- attributes(i) attributes(y) <- attributes(i)
return_after_integrity_check(y, "antiviral agent code", AMR_env$AV_lookup$av) return_after_integrity_check(y, "antimicrobial code", AMR_env$AV_lookup$av)
} }
#' @method [[<- av #' @method [[<- av
#' @export #' @export
@ -565,7 +564,7 @@ as.data.frame.av <- function(x, ...) {
"[[<-.av" <- function(i, j, ..., value) { "[[<-.av" <- function(i, j, ..., value) {
y <- NextMethod() y <- NextMethod()
attributes(y) <- attributes(i) attributes(y) <- attributes(i)
return_after_integrity_check(y, "antiviral agent code", AMR_env$AV_lookup$av) return_after_integrity_check(y, "antimicrobial code", AMR_env$AV_lookup$av)
} }
#' @method c av #' @method c av
#' @export #' @export
@ -574,7 +573,7 @@ c.av <- function(...) {
x <- list(...)[[1L]] x <- list(...)[[1L]]
y <- NextMethod() y <- NextMethod()
attributes(y) <- attributes(x) attributes(y) <- attributes(x)
return_after_integrity_check(y, "antiviral agent code", AMR_env$AV_lookup$av) return_after_integrity_check(y, "antimicrobial code", AMR_env$AV_lookup$av)
} }
#' @method unique av #' @method unique av

View File

@ -130,11 +130,35 @@ av_group <- function(x, language = get_AMR_locale(), ...) {
} }
#' @rdname av_property #' @rdname av_property
#' @aliases ATC
#' @export #' @export
av_atc <- function(x, ...) { av_atc <- function(x, only_first = FALSE, ...) {
meet_criteria(x, allow_NA = TRUE) meet_criteria(x, allow_NA = TRUE)
# ATCs in the antivirals data set are not a list meet_criteria(only_first, allow_class = "logical", has_length = 1)
av_validate(x = x, property = "atc", ...)
atcs <- av_validate(x = x, property = "atc", ...)
if (only_first == TRUE) {
atcs <- vapply(
FUN.VALUE = character(1),
# get only the first ATC code
atcs,
function(x) {
# try to get the J-group
if (any(x %like% "^J")) {
x[x %like% "^J"][1L]
} else {
as.character(x[1L])
}
}
)
} else if (length(atcs) == 1) {
atcs <- unname(unlist(atcs))
} else {
names(atcs) <- x
}
atcs
} }
#' @rdname av_property #' @rdname av_property
@ -157,7 +181,20 @@ av_ddd <- function(x, administration = "oral", ...) {
meet_criteria(administration, is_in = c("oral", "iv"), has_length = 1) meet_criteria(administration, is_in = c("oral", "iv"), has_length = 1)
x <- as.av(x, ...) x <- as.av(x, ...)
ddd_prop <- paste0(administration, "_ddd") ddd_prop <- administration
# old behaviour
units <- list(...)$units
if (!is.null(units) && isTRUE(units)) {
if (message_not_thrown_before("av_ddd", entire_session = TRUE)) {
warning_(
"in `av_ddd()`: using `av_ddd(..., units = TRUE)` is deprecated, use `av_ddd_units()` to retrieve units instead.",
"This warning will be shown once per session."
)
}
ddd_prop <- paste0(ddd_prop, "_units")
} else {
ddd_prop <- paste0(ddd_prop, "_ddd")
}
out <- av_validate(x = x, property = ddd_prop) out <- av_validate(x = x, property = ddd_prop)
if (any(av_name(x, language = NULL) %like% "/" & is.na(out))) { if (any(av_name(x, language = NULL) %like% "/" & is.na(out))) {
@ -177,17 +214,16 @@ av_ddd_units <- function(x, administration = "oral", ...) {
meet_criteria(administration, is_in = c("oral", "iv"), has_length = 1) meet_criteria(administration, is_in = c("oral", "iv"), has_length = 1)
x <- as.av(x, ...) x <- as.av(x, ...)
ddd_prop <- paste0(administration, "_units") if (any(av_name(x, language = NULL) %like% "/")) {
out <- av_validate(x = x, property = ddd_prop)
if (any(av_name(x, language = NULL) %like% "/" & is.na(out))) {
warning_( warning_(
"in `av_ddd_units()`: DDDs of some combined products are available for different dose combinations and not (yet) part of the AMR package.", "in `av_ddd_units()`: DDDs of combined products are available for different dose combinations and not (yet) part of the AMR package.",
"Please refer to the WHOCC website:\n", "Please refer to the WHOCC website:\n",
"www.whocc.no/ddd/list_of_ddds_combined_products/" "www.whocc.no/ddd/list_of_ddds_combined_products/"
) )
} }
out
ddd_prop <- paste0(administration, "_units")
av_validate(x = x, property = ddd_prop)
} }
#' @rdname av_property #' @rdname av_property

View File

@ -70,20 +70,6 @@ vec_cast.ab.character <- function(x, to, ...) {
return_after_integrity_check(x, "antimicrobial code", as.character(AMR_env$AB_lookup$ab)) return_after_integrity_check(x, "antimicrobial code", as.character(AMR_env$AB_lookup$ab))
} }
# S3: av
vec_ptype2.character.av <- function(x, y, ...) {
x
}
vec_ptype2.av.character <- function(x, y, ...) {
y
}
vec_cast.character.av <- function(x, to, ...) {
as.character(x)
}
vec_cast.av.character <- function(x, to, ...) {
return_after_integrity_check(x, "antiviral agent code", as.character(AMR_env$AV_lookup$av))
}
# S3: mo # S3: mo
vec_ptype2.character.mo <- function(x, y, ...) { vec_ptype2.character.mo <- function(x, y, ...) {
x x

12
R/zzz.R
View File

@ -50,11 +50,6 @@ AMR_env$ab_previously_coerced <- data.frame(
ab = character(0), ab = character(0),
stringsAsFactors = FALSE stringsAsFactors = FALSE
) )
AMR_env$av_previously_coerced <- data.frame(
x = character(0),
av = character(0),
stringsAsFactors = FALSE
)
AMR_env$rsi_interpretation_history <- data.frame( AMR_env$rsi_interpretation_history <- data.frame(
datetime = Sys.time()[0], datetime = Sys.time()[0],
index = integer(0), index = integer(0),
@ -92,13 +87,11 @@ if (utf8_supported && !is_latex) {
# developers of the vctrs package: # developers of the vctrs package:
# https://github.com/r-lib/vctrs/blob/05968ce8e669f73213e3e894b5f4424af4f46316/R/register-s3.R # https://github.com/r-lib/vctrs/blob/05968ce8e669f73213e3e894b5f4424af4f46316/R/register-s3.R
s3_register("pillar::pillar_shaft", "ab") s3_register("pillar::pillar_shaft", "ab")
s3_register("pillar::pillar_shaft", "av")
s3_register("pillar::pillar_shaft", "mo") s3_register("pillar::pillar_shaft", "mo")
s3_register("pillar::pillar_shaft", "rsi") s3_register("pillar::pillar_shaft", "rsi")
s3_register("pillar::pillar_shaft", "mic") s3_register("pillar::pillar_shaft", "mic")
s3_register("pillar::pillar_shaft", "disk") s3_register("pillar::pillar_shaft", "disk")
s3_register("tibble::type_sum", "ab") s3_register("tibble::type_sum", "ab")
s3_register("tibble::type_sum", "av")
s3_register("tibble::type_sum", "mo") s3_register("tibble::type_sum", "mo")
s3_register("tibble::type_sum", "rsi") s3_register("tibble::type_sum", "rsi")
s3_register("tibble::type_sum", "mic") s3_register("tibble::type_sum", "mic")
@ -136,11 +129,6 @@ if (utf8_supported && !is_latex) {
s3_register("vctrs::vec_ptype2", "ab.character") s3_register("vctrs::vec_ptype2", "ab.character")
s3_register("vctrs::vec_cast", "character.ab") s3_register("vctrs::vec_cast", "character.ab")
s3_register("vctrs::vec_cast", "ab.character") s3_register("vctrs::vec_cast", "ab.character")
# S3: av
s3_register("vctrs::vec_ptype2", "character.av")
s3_register("vctrs::vec_ptype2", "av.character")
s3_register("vctrs::vec_cast", "character.av")
s3_register("vctrs::vec_cast", "av.character")
# S3: mo # S3: mo
s3_register("vctrs::vec_ptype2", "character.mo") s3_register("vctrs::vec_ptype2", "character.mo")
s3_register("vctrs::vec_ptype2", "mo.character") s3_register("vctrs::vec_ptype2", "mo.character")

View File

@ -8,6 +8,7 @@
\alias{av_tradenames} \alias{av_tradenames}
\alias{av_group} \alias{av_group}
\alias{av_atc} \alias{av_atc}
\alias{ATC}
\alias{av_loinc} \alias{av_loinc}
\alias{av_ddd} \alias{av_ddd}
\alias{av_ddd_units} \alias{av_ddd_units}
@ -25,7 +26,7 @@ av_tradenames(x, ...)
av_group(x, language = get_AMR_locale(), ...) av_group(x, language = get_AMR_locale(), ...)
av_atc(x, ...) av_atc(x, only_first = FALSE, ...)
av_loinc(x, ...) av_loinc(x, ...)