2021-07-23 21:42:11 +02:00
|
|
|
# ==================================================================== #
|
2023-07-08 17:30:05 +02:00
|
|
|
# TITLE: #
|
2022-10-05 09:12:22 +02:00
|
|
|
# AMR: An R Package for Working with Antimicrobial Resistance Data #
|
2021-07-23 21:42:11 +02:00
|
|
|
# #
|
2023-07-08 17:30:05 +02:00
|
|
|
# SOURCE CODE: #
|
2021-07-23 21:42:11 +02:00
|
|
|
# https://github.com/msberends/AMR #
|
|
|
|
# #
|
2023-07-08 17:30:05 +02:00
|
|
|
# PLEASE CITE THIS SOFTWARE AS: #
|
2022-10-05 09:12:22 +02:00
|
|
|
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
|
|
|
|
# (2022). AMR: An R Package for Working with Antimicrobial Resistance #
|
|
|
|
# Data. Journal of Statistical Software, 104(3), 1-31. #
|
2023-05-27 10:39:22 +02:00
|
|
|
# https://doi.org/10.18637/jss.v104.i03 #
|
2022-10-05 09:12:22 +02:00
|
|
|
# #
|
2022-12-27 15:16:15 +01:00
|
|
|
# Developed at the University of Groningen and the University Medical #
|
|
|
|
# Center Groningen in The Netherlands, in collaboration with many #
|
|
|
|
# colleagues from around the world, see our website. #
|
2021-07-23 21:42:11 +02:00
|
|
|
# #
|
|
|
|
# This R package is free software; you can freely use and distribute #
|
|
|
|
# it for both personal and commercial purposes under the terms of the #
|
|
|
|
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
|
|
|
# the Free Software Foundation. #
|
|
|
|
# We created this package for both routine data analysis and academic #
|
|
|
|
# research and it was publicly released in the hope that it will be #
|
|
|
|
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
|
|
|
# #
|
|
|
|
# Visit our website for the full manual and a complete tutorial about #
|
|
|
|
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
|
|
|
# ==================================================================== #
|
|
|
|
|
2022-08-28 10:31:50 +02:00
|
|
|
# These are all S3 implementations for the vctrs package,
|
2021-07-23 21:42:11 +02:00
|
|
|
# that is used internally by tidyverse packages such as dplyr.
|
|
|
|
# They are to convert AMR-specific classes to bare characters and integers.
|
|
|
|
# All of them will be exported using s3_register() in R/zzz.R when loading the package.
|
|
|
|
|
2021-12-11 13:41:31 +01:00
|
|
|
# see https://github.com/tidyverse/dplyr/issues/5955 why this is required
|
2022-08-21 16:37:20 +02:00
|
|
|
|
2024-02-24 18:51:37 +01:00
|
|
|
# S3: ab_selector ----
|
|
|
|
# this does not need a .default method since it's used internally only
|
|
|
|
vec_ptype2.character.ab_selector <- function(x, y, ...) {
|
2021-12-11 13:41:31 +01:00
|
|
|
x
|
|
|
|
}
|
2024-02-24 18:51:37 +01:00
|
|
|
vec_ptype2.ab_selector.character <- function(x, y, ...) {
|
|
|
|
y
|
2021-12-11 13:41:31 +01:00
|
|
|
}
|
|
|
|
vec_cast.character.ab_selector <- function(x, to, ...) {
|
|
|
|
unclass(x)
|
|
|
|
}
|
|
|
|
|
2024-02-24 18:51:37 +01:00
|
|
|
# S3: ab_selector_any_all ----
|
|
|
|
# this does not need a .default method since it's used internally only
|
|
|
|
vec_ptype2.logical.ab_selector_any_all <- function(x, y, ...) {
|
2022-08-21 16:37:20 +02:00
|
|
|
x
|
|
|
|
}
|
2024-02-24 18:51:37 +01:00
|
|
|
vec_ptype2.ab_selector_any_all.logical <- function(x, y, ...) {
|
|
|
|
y
|
2022-08-21 16:37:20 +02:00
|
|
|
}
|
|
|
|
vec_cast.logical.ab_selector_any_all <- function(x, to, ...) {
|
|
|
|
unclass(x)
|
|
|
|
}
|
|
|
|
|
2024-02-24 18:51:37 +01:00
|
|
|
# S3: ab ----
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.ab.default <- function (x, y, ..., x_arg = "", y_arg = "") {
|
2021-07-23 21:42:11 +02:00
|
|
|
x
|
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.ab.ab <- function(x, y, ...) {
|
|
|
|
x
|
2021-07-23 21:42:11 +02:00
|
|
|
}
|
|
|
|
vec_cast.character.ab <- function(x, to, ...) {
|
2022-10-31 11:19:06 +01:00
|
|
|
as.character(x)
|
|
|
|
}
|
|
|
|
vec_cast.ab.character <- function(x, to, ...) {
|
2022-11-13 13:44:25 +01:00
|
|
|
return_after_integrity_check(x, "antimicrobial drug code", as.character(AMR_env$AB_lookup$ab))
|
2021-07-23 21:42:11 +02:00
|
|
|
}
|
|
|
|
|
2024-02-24 18:51:37 +01:00
|
|
|
# S3: av ----
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.av.default <- function (x, y, ..., x_arg = "", y_arg = "") {
|
2022-11-13 08:46:10 +01:00
|
|
|
x
|
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.av.av <- function(x, y, ...) {
|
|
|
|
x
|
2022-11-13 08:46:10 +01:00
|
|
|
}
|
|
|
|
vec_cast.character.av <- function(x, to, ...) {
|
|
|
|
as.character(x)
|
|
|
|
}
|
|
|
|
vec_cast.av.character <- function(x, to, ...) {
|
2022-11-13 13:44:25 +01:00
|
|
|
return_after_integrity_check(x, "antiviral drug code", as.character(AMR_env$AV_lookup$av))
|
2022-11-13 08:46:10 +01:00
|
|
|
}
|
|
|
|
|
2024-02-24 18:51:37 +01:00
|
|
|
# S3: mo ----
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.mo.default <- function (x, y, ..., x_arg = "", y_arg = "") {
|
2021-07-23 21:42:11 +02:00
|
|
|
x
|
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.mo.mo <- function(x, y, ...) {
|
|
|
|
x
|
2021-07-23 21:42:11 +02:00
|
|
|
}
|
|
|
|
vec_cast.character.mo <- function(x, to, ...) {
|
2022-10-31 11:19:06 +01:00
|
|
|
as.character(x)
|
|
|
|
}
|
|
|
|
vec_cast.mo.character <- function(x, to, ...) {
|
2023-01-21 23:47:20 +01:00
|
|
|
add_MO_lookup_to_AMR_env()
|
2022-12-27 15:16:15 +01:00
|
|
|
return_after_integrity_check(x, "microorganism code", as.character(AMR_env$MO_lookup$mo))
|
2021-07-23 21:42:11 +02:00
|
|
|
}
|
|
|
|
|
2024-02-24 18:51:37 +01:00
|
|
|
# S3: disk ----
|
2024-04-05 16:44:43 +02:00
|
|
|
vec_ptype_full.disk <- function(x, ...) {
|
|
|
|
"disk"
|
|
|
|
}
|
|
|
|
vec_ptype_abbr.disk <- function(x, ...) {
|
2024-05-30 15:50:17 +02:00
|
|
|
"dsk"
|
2024-04-05 16:44:43 +02:00
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.disk.default <- function (x, y, ..., x_arg = "", y_arg = "") {
|
2024-06-15 15:33:49 +02:00
|
|
|
NA_disk_[0]
|
2021-07-23 21:42:11 +02:00
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.disk.disk <- function(x, y, ...) {
|
2024-06-15 15:33:49 +02:00
|
|
|
NA_disk_[0]
|
|
|
|
}
|
|
|
|
vec_cast.disk.disk <- function(x, to, ...) {
|
|
|
|
as.disk(x)
|
2021-07-23 21:42:11 +02:00
|
|
|
}
|
|
|
|
vec_cast.integer.disk <- function(x, to, ...) {
|
|
|
|
unclass(x)
|
|
|
|
}
|
2022-10-31 11:19:06 +01:00
|
|
|
vec_cast.disk.integer <- function(x, to, ...) {
|
|
|
|
as.disk(x)
|
|
|
|
}
|
|
|
|
vec_cast.double.disk <- function(x, to, ...) {
|
|
|
|
unclass(x)
|
|
|
|
}
|
|
|
|
vec_cast.disk.double <- function(x, to, ...) {
|
|
|
|
as.disk(x)
|
|
|
|
}
|
|
|
|
vec_cast.character.disk <- function(x, to, ...) {
|
|
|
|
unclass(x)
|
|
|
|
}
|
|
|
|
vec_cast.disk.character <- function(x, to, ...) {
|
|
|
|
as.disk(x)
|
|
|
|
}
|
2022-08-30 21:48:02 +02:00
|
|
|
|
2024-02-24 18:51:37 +01:00
|
|
|
# S3: mic ----
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.mic.default <- function (x, y, ..., x_arg = "", y_arg = "") {
|
2024-04-05 16:44:43 +02:00
|
|
|
# this will make sure that currently implemented MIC levels are returned
|
2024-06-15 15:33:49 +02:00
|
|
|
NA_mic_[0]
|
2024-02-24 15:16:52 +01:00
|
|
|
}
|
|
|
|
vec_ptype2.mic.mic <- function(x, y, ...) {
|
2024-04-05 16:44:43 +02:00
|
|
|
# this will make sure that currently implemented MIC levels are returned
|
2024-06-15 15:33:49 +02:00
|
|
|
NA_mic_[0]
|
2024-04-05 16:44:43 +02:00
|
|
|
}
|
|
|
|
vec_cast.mic.mic <- function(x, to, ...) {
|
|
|
|
# this will make sure that currently implemented MIC levels are returned
|
|
|
|
as.mic(x)
|
2024-02-24 15:16:52 +01:00
|
|
|
}
|
2022-08-30 21:48:02 +02:00
|
|
|
vec_cast.character.mic <- function(x, to, ...) {
|
|
|
|
as.character(x)
|
|
|
|
}
|
|
|
|
vec_cast.double.mic <- function(x, to, ...) {
|
|
|
|
as.double(x)
|
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_cast.integer.mic <- function(x, to, ...) {
|
|
|
|
as.integer(x)
|
|
|
|
}
|
2024-04-07 20:22:59 +02:00
|
|
|
vec_cast.factor.mic <- function(x, to, ...) {
|
|
|
|
factor(as.character(x))
|
|
|
|
}
|
2022-10-31 11:19:06 +01:00
|
|
|
vec_cast.mic.double <- function(x, to, ...) {
|
|
|
|
as.mic(x)
|
|
|
|
}
|
|
|
|
vec_cast.mic.character <- function(x, to, ...) {
|
|
|
|
as.mic(x)
|
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_cast.mic.integer <- function(x, to, ...) {
|
|
|
|
as.mic(x)
|
|
|
|
}
|
2024-04-07 20:22:59 +02:00
|
|
|
vec_cast.mic.factor <- function(x, to, ...) {
|
|
|
|
as.mic(x)
|
|
|
|
}
|
2022-08-30 21:48:02 +02:00
|
|
|
vec_math.mic <- function(.fn, x, ...) {
|
|
|
|
.fn(as.double(x), ...)
|
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_arith.mic <- function(op, x, y, ...) {
|
|
|
|
vctrs::vec_arith(op, as.double(x), as.double(y))
|
|
|
|
}
|
2022-10-31 11:19:06 +01:00
|
|
|
|
2024-02-24 18:51:37 +01:00
|
|
|
# S3: sir ----
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.sir.default <- function (x, y, ..., x_arg = "", y_arg = "") {
|
2024-06-13 20:55:17 +02:00
|
|
|
NA_sir_[0]
|
2022-10-31 11:19:06 +01:00
|
|
|
}
|
2024-02-24 15:16:52 +01:00
|
|
|
vec_ptype2.sir.sir <- function(x, y, ...) {
|
2024-06-13 20:55:17 +02:00
|
|
|
NA_sir_[0]
|
|
|
|
}
|
|
|
|
vec_ptype2.character.sir <- function(x, y, ...) {
|
|
|
|
NA_sir_[0]
|
2022-10-31 11:19:06 +01:00
|
|
|
}
|
2024-06-15 15:33:49 +02:00
|
|
|
vec_cast.sir.sir <- function(x, to, ...) {
|
|
|
|
# this makes sure that old SIR objects (with S/I/R) are converted to the current structure (S/SDD/I/R/NI)
|
|
|
|
as.sir(x)
|
|
|
|
}
|
2023-01-21 23:47:20 +01:00
|
|
|
vec_cast.character.sir <- function(x, to, ...) {
|
2022-10-31 11:19:06 +01:00
|
|
|
as.character(x)
|
|
|
|
}
|
2023-01-21 23:47:20 +01:00
|
|
|
vec_cast.sir.character <- function(x, to, ...) {
|
|
|
|
as.sir(x)
|
2022-10-31 11:19:06 +01:00
|
|
|
}
|