mirror of https://github.com/msberends/AMR
parent
9a381c8d18
commit
d8c91d5876
Binary file not shown.
@ -0,0 +1,47 @@ |
||||
# ==================================================================== # |
||||
# TITLE # |
||||
# Antimicrobial Resistance (AMR) Data Analysis for R # |
||||
# # |
||||
# SOURCE # |
||||
# https://github.com/msberends/AMR # |
||||
# # |
||||
# LICENCE # |
||||
# (c) 2018-2021 Berends MS, Luz CF et al. # |
||||
# Developed at the University of Groningen, the Netherlands, in # |
||||
# collaboration with non-profit organisations Certe Medical # |
||||
# Diagnostics & Advice, and University Medical Center Groningen. # |
||||
# # |
||||
# 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/ # |
||||
# ==================================================================== # |
||||
|
||||
pkg_suggests <- trimws(unlist(strsplit(packageDescription("AMR")$Suggests, ",(\n)?"))) |
||||
|
||||
to_install <- pkg_suggests[!pkg_suggests %in% rownames(utils::installed.packages())] |
||||
to_update <- as.data.frame(old.packages(), stringsAsFactors = FALSE) |
||||
|
||||
for (i in seq_len(length(to_install))) { |
||||
cat("Installing package", to_install[i], "\n") |
||||
tryCatch(install.packages(to_install[i], repos = "https://cran.rstudio.com/", dependencies = TRUE, quiet = TRUE), |
||||
message = function(m) invisible(), |
||||
warning = function(w) message(w$message), |
||||
error = function(e) message(e$message)) |
||||
} |
||||
|
||||
for (i in seq_len(length(to_update))) { |
||||
cat("Updating package", to_install[i], "\n") |
||||
tryCatch(update.packages(to_update[i], repos = "https://cran.rstudio.com/", ask = FALSE), |
||||
message = function(m) invisible(), |
||||
warning = function(w) message(w$message), |
||||
error = function(e) message(e$message)) |
||||
} |
||||
|
||||
# saveRDS(to_update, ".github/depends.Rds", version = 2) |
@ -0,0 +1,39 @@ |
||||
# ==================================================================== # |
||||
# TITLE # |
||||
# Antimicrobial Resistance (AMR) Data Analysis for R # |
||||
# # |
||||
# SOURCE # |
||||
# https://github.com/msberends/AMR # |
||||
# # |
||||
# LICENCE # |
||||
# (c) 2018-2021 Berends MS, Luz CF et al. # |
||||
# Developed at the University of Groningen, the Netherlands, in # |
||||
# collaboration with non-profit organisations Certe Medical # |
||||
# Diagnostics & Advice, and University Medical Center Groningen. # |
||||
# # |
||||
# 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/ # |
||||
# ==================================================================== # |
||||
|
||||
expect_identical(suppressWarnings(p_symbol(c(0.001, 0.01, 0.05, 0.1, 1, NA, 3))), |
||||
c("***", "**", "*", ".", " ", NA, NA)) |
||||
|
||||
expect_warning(key_antibiotics(example_isolates)) |
||||
expect_identical(suppressWarnings(key_antibiotics(example_isolates)), |
||||
key_antimicrobials(example_isolates, antifungal = NULL)) |
||||
|
||||
expect_warning(key_antibiotics_equal("S", "S")) |
||||
expect_identical(suppressWarnings(key_antibiotics_equal("S", "S")), |
||||
antimicrobials_equal("S", "S", type = "keyantimicrobials")) |
||||
|
||||
expect_warning(filter_first_weighted_isolate(example_isolates)) |
||||
expect_identical(suppressWarnings(filter_first_weighted_isolate(example_isolates)), |
||||
filter_first_isolate(example_isolates)) |
@ -0,0 +1,63 @@ |
||||
# ==================================================================== # |
||||
# TITLE # |
||||
# Antimicrobial Resistance (AMR) Data Analysis for R # |
||||
# # |
||||
# SOURCE # |
||||
# https://github.com/msberends/AMR # |
||||
# # |
||||
# LICENCE # |
||||
# (c) 2018-2021 Berends MS, Luz CF et al. # |
||||
# Developed at the University of Groningen, the Netherlands, in # |
||||
# collaboration with non-profit organisations Certe Medical # |
||||
# Diagnostics & Advice, and University Medical Center Groningen. # |
||||
# # |
||||
# 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/ # |
||||
# ==================================================================== # |
||||
|
||||
expect_identical(ab_name("AMX", language = NULL), "Amoxicillin") |
||||
expect_identical(as.character(ab_atc("AMX")), "J01CA04") |
||||
expect_identical(ab_cid("AMX"), as.integer(33613)) |
||||
|
||||
expect_inherits(ab_tradenames("AMX"), "character") |
||||
expect_inherits(ab_tradenames(c("AMX", "AMX")), "list") |
||||
|
||||
expect_identical(ab_group("AMX", language = NULL), "Beta-lactams/penicillins") |
||||
expect_identical(ab_atc_group1("AMX", language = NULL), "Beta-lactam antibacterials, penicillins") |
||||
expect_identical(ab_atc_group2("AMX", language = NULL), "Penicillins with extended spectrum") |
||||
|
||||
expect_identical(ab_name("Fluclox", language = NULL), "Flucloxacillin") |
||||
expect_identical(ab_name("fluklox", language = NULL), "Flucloxacillin") |
||||
expect_identical(ab_name("floxapen", language = NULL), "Flucloxacillin") |
||||
expect_identical(ab_name(21319, language = NULL), "Flucloxacillin") |
||||
expect_identical(ab_name("J01CF05", language = NULL), "Flucloxacillin") |
||||
|
||||
expect_identical(ab_ddd("AMX", "oral"), 1.5) |
||||
expect_identical(ab_ddd("AMX", "oral", units = TRUE), "g") |
||||
expect_identical(ab_ddd("AMX", "iv"), 3) |
||||
expect_identical(ab_ddd("AMX", "iv", units = TRUE), "g") |
||||
|
||||
expect_identical(ab_name(x = c("AMC", "PLB"), language = NULL), c("Amoxicillin/clavulanic acid", "Polymyxin B")) |
||||
expect_identical(ab_name(x = c("AMC", "PLB"), tolower = TRUE, language = NULL), |
||||
c("amoxicillin/clavulanic acid", "polymyxin B")) |
||||
|
||||
expect_inherits(ab_info("AMX"), "list") |
||||
|
||||
expect_error(ab_property("amox", "invalid property")) |
||||
expect_error(ab_name("amox", language = "INVALID")) |
||||
expect_stdout(print(ab_name("amox", language = NULL))) |
||||
|
||||
expect_equal(ab_name("21066-6", language = NULL), "Ampicillin") |
||||
expect_equal(ab_loinc("ampicillin"), |
||||
c("21066-6", "3355-5", "33562-0", "33919-2", "43883-8", "43884-6", "87604-5")) |
||||
|
||||
expect_true(ab_url("AMX") %like% "whocc.no") |
||||
expect_warning(ab_url("ASP")) |
@ -0,0 +1,99 @@ |
||||
# ==================================================================== # |
||||
# TITLE # |
||||
# Antimicrobial Resistance (AMR) Data Analysis for R # |
||||
# # |
||||
# SOURCE # |
||||
# https://github.com/msberends/AMR # |
||||
# # |
||||
# LICENCE # |
||||
# (c) 2018-2021 Berends MS, Luz CF et al. # |
||||
# Developed at the University of Groningen, the Netherlands, in # |
||||
# collaboration with non-profit organisations Certe Medical # |
||||
# Diagnostics & Advice, and University Medical Center Groningen. # |
||||
# # |
||||
# 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/ # |
||||
# ==================================================================== # |
||||
|
||||
expect_equal(count_resistant(example_isolates$AMX), count_R(example_isolates$AMX)) |
||||
expect_equal(count_susceptible(example_isolates$AMX), count_SI(example_isolates$AMX)) |
||||
expect_equal(count_all(example_isolates$AMX), n_rsi(example_isolates$AMX)) |
||||
|
||||
# AMX resistance in `example_isolates` |
||||
expect_equal(count_R(example_isolates$AMX), 804) |
||||
expect_equal(count_I(example_isolates$AMX), 3) |
||||
expect_equal(suppressWarnings(count_S(example_isolates$AMX)), 543) |
||||
expect_equal(count_R(example_isolates$AMX) + count_I(example_isolates$AMX), |
||||
suppressWarnings(count_IR(example_isolates$AMX))) |
||||
expect_equal(suppressWarnings(count_S(example_isolates$AMX)) + count_I(example_isolates$AMX), |
||||
count_SI(example_isolates$AMX)) |
||||
|
||||
|
||||
# warning for speed loss |
||||
reset_all_thrown_messages() |
||||
expect_warning(count_resistant(as.character(example_isolates$AMC))) |
||||
reset_all_thrown_messages() |
||||
expect_warning(count_resistant(example_isolates$AMC, |
||||
as.character(example_isolates$GEN))) |
||||
|
||||
# check for errors |
||||
expect_error(count_resistant("test", minimum = "test")) |
||||
expect_error(count_resistant("test", as_percent = "test")) |
||||
expect_error(count_susceptible("test", minimum = "test")) |
||||
expect_error(count_susceptible("test", as_percent = "test")) |
||||
|
||||
expect_error(count_df(c("A", "B", "C"))) |
||||
expect_error(count_df(example_isolates[, "date"])) |
||||
|
||||
if (suppressWarnings(require("dplyr"))) { |
||||
expect_equal(example_isolates %>% count_susceptible(AMC), 1433) |
||||
expect_equal(example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = TRUE), 1687) |
||||
expect_equal(example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = FALSE), 1764) |
||||
expect_equal(example_isolates %>% count_all(AMC, GEN, only_all_tested = TRUE), 1798) |
||||
expect_equal(example_isolates %>% count_all(AMC, GEN, only_all_tested = FALSE), 1936) |
||||
expect_identical(example_isolates %>% count_all(AMC, GEN, only_all_tested = TRUE), |
||||
example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = TRUE) + |
||||
example_isolates %>% count_resistant(AMC, GEN, only_all_tested = TRUE)) |
||||
|
||||
# count of cases |
||||
expect_equal(example_isolates %>% |
||||
group_by(hospital_id) %>% |
||||
summarise(cipro = count_susceptible(CIP), |
||||
genta = count_susceptible(GEN), |
||||
combination = count_susceptible(CIP, GEN)) %>% |
||||
pull(combination), |
||||
c(253, 465, 192, 558)) |
||||
|
||||
# count_df |
||||
expect_equal( |
||||
example_isolates %>% select(AMX) %>% count_df() %>% pull(value), |
||||
c(example_isolates$AMX %>% count_susceptible(), |
||||
example_isolates$AMX %>% count_resistant()) |
||||
) |
||||
expect_equal( |
||||
example_isolates %>% select(AMX) %>% count_df(combine_IR = TRUE) %>% pull(value), |
||||
c(suppressWarnings(example_isolates$AMX %>% count_S()), |
||||
suppressWarnings(example_isolates$AMX %>% count_IR())) |
||||
) |
||||
expect_equal( |
||||
example_isolates %>% select(AMX) %>% count_df(combine_SI = FALSE) %>% pull(value), |
||||
c(suppressWarnings(example_isolates$AMX %>% count_S()), |
||||
example_isolates$AMX %>% count_I(), |
||||
example_isolates$AMX %>% count_R()) |
||||
) |
||||
|
||||
# grouping in rsi_calc_df() (= backbone of rsi_df()) |
||||
expect_true("hospital_id" %in% (example_isolates %>% |
||||
group_by(hospital_id) %>% |
||||
select(hospital_id, AMX, CIP, gender) %>% |
||||
rsi_df() %>% |
||||
colnames())) |
||||
} |