1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 18:41:58 +02:00

dplyr 0.8.0 support, fixes #7

This commit is contained in:
2018-12-22 22:39:34 +01:00
parent b937662a97
commit 0b8084871d
29 changed files with 555 additions and 479 deletions

View File

@ -20,17 +20,17 @@ context("age.R")
test_that("age works", {
expect_equal(age(x = c("1980-01-01", "1985-01-01", "1990-01-01"),
y = "2019-01-01"),
reference = "2019-01-01"),
c(39, 34, 29))
expect_error(age(x = c("1980-01-01", "1985-01-01", "1990-01-01"),
y = c("2019-01-01", "2019-01-01")))
reference = c("2019-01-01", "2019-01-01")))
expect_error(age(x = c("1980-01-01", "1985-01-01", "1990-01-01"),
y = "1975-01-01"))
reference = "1975-01-01"))
expect_warning(age(x = c("1800-01-01", "1805-01-01", "1810-01-01"),
y = "2019-01-01"))
reference = "2019-01-01"))
})
test_that("age_groups works", {

View File

@ -20,11 +20,6 @@ context("deprecated.R")
test_that("deprecated functions work", {
expect_identical(is.mo(as.mo("esco")), suppressWarnings(is.bactid(as.bactid("esco"))))
expect_warning(identical(is.mo(as.mo("esco")), is.bactid(as.bactid("esco"))))
expect_identical(as.mo("esco"), suppressWarnings(guess_bactid("esco")))
expect_error(suppressWarnings(ratio("A")))
expect_error(suppressWarnings(ratio(1, ratio = "abc")))
expect_error(suppressWarnings(ratio(c(1, 2), ratio = c(1, 2, 3))))
@ -32,13 +27,4 @@ test_that("deprecated functions work", {
expect_identical(suppressWarnings(ratio(c(772, 1611, 737), ratio = "1:2:1")), c(780, 1560, 780))
expect_identical(suppressWarnings(ratio(c(1752, 1895), ratio = c(1, 1))), c(1823.5, 1823.5))
old_mo <- "ESCCOL"
class(old_mo) <- "bactid"
df_oldmo <- data.frame(test = old_mo)
# print
expect_output(print(old_mo))
# test pull
library(dplyr)
expect_identical(df_oldmo %>% pull(test), old_mo)
})

View File

@ -19,7 +19,7 @@
context("first_isolate.R")
test_that("first isolates work", {
# septic_patients contains 1331 out of 2000 first isolates
# septic_patients contains 1315 out of 2000 first isolates
expect_equal(
sum(
first_isolate(tbl = septic_patients,
@ -139,16 +139,15 @@ test_that("first isolates work", {
mutate(first = first_isolate(., "date", "patient_id",
col_mo = "mo",
col_specimen = "specimen",
filter_specimen = "something_unexisting",
output_logical = FALSE)))
filter_specimen = "something_unexisting")))
# printing of exclusion message
expect_output(septic_patients %>%
first_isolate(col_date = "date",
col_mo = "mo",
col_patient_id = "patient_id",
col_testcode = "gender",
testcodes_exclude = "M"))
first_isolate(col_date = "date",
col_mo = "mo",
col_patient_id = "patient_id",
col_testcode = "gender",
testcodes_exclude = "M"))
# errors
expect_error(first_isolate("date", "patient_id", col_mo = "mo"))
@ -158,18 +157,16 @@ test_that("first isolates work", {
# look for columns itself
expect_message(first_isolate(septic_patients))
expect_message(first_isolate(septic_patients %>%
mutate(mo = as.character(mo)) %>%
left_join_microorganisms(),
col_genus = "genus",
col_species = "species"))
expect_error(first_isolate(septic_patients %>%
mutate(mo = as.character(mo)) %>%
left_join_microorganisms()))
# if mo is not an mo class, result should be the same
expect_identical(septic_patients %>%
mutate(mo = as.character(mo)) %>%
first_isolate(col_date = "date",
col_mo = "mo",
col_patient_id = "patient_id"),
mutate(mo = as.character(mo)) %>%
first_isolate(col_date = "date",
col_mo = "mo",
col_patient_id = "patient_id"),
septic_patients %>%
first_isolate(col_date = "date",
col_mo = "mo",

View File

@ -21,8 +21,8 @@ context("mdro.R")
test_that("mdro works", {
library(dplyr)
expect_error(suppressWarnings(mdro(septic_patients, "invalid", col_bactid = "mo", info = TRUE)))
expect_error(suppressWarnings(mdro(septic_patients, "fr", col_bactid = "mo", info = TRUE)))
expect_error(suppressWarnings(mdro(septic_patients, "invalid", col_mo = "mo", info = TRUE)))
expect_error(suppressWarnings(mdro(septic_patients, "fr", info = TRUE)))
expect_error(suppressWarnings(mdro(septic_patients, country = c("de", "nl"), info = TRUE)))
expect_error(suppressWarnings(mdro(septic_patients, col_mo = "invalid", info = TRUE)))

View File

@ -147,53 +147,3 @@ test_that("old rsi works", {
})
test_that("prediction of rsi works", {
amox_R <- septic_patients %>%
filter(mo == "B_ESCHR_COL") %>%
rsi_predict(col_ab = "amox",
col_date = "date",
minimum = 10,
info = TRUE) %>%
pull("value")
# amox resistance will increase according to data set `septic_patients`
expect_true(amox_R[3] < amox_R[20])
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "binomial",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "loglin",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "lin",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "INVALID MODEL",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "NOT EXISTING COLUMN",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "amox",
col_date = "NOT EXISTING COLUMN",
info = TRUE))
# almost all E. coli are mero S in the Netherlands :)
expect_error(resistance_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "mero",
col_date = "date",
info = TRUE))
expect_error(portion_df(c("A", "B", "C")))
expect_error(portion_df(septic_patients[,"date"]))
})

View File

@ -0,0 +1,71 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This package is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This R package is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License version 2.0 for more details. #
# ==================================================================== #
context("portion.R")
test_that("prediction of rsi works", {
amox_R <- septic_patients %>%
filter(mo == "B_ESCHR_COL") %>%
rsi_predict(col_ab = "amox",
col_date = "date",
minimum = 10,
info = TRUE) %>%
pull("value")
# amox resistance will increase according to data set `septic_patients`
expect_true(amox_R[3] < amox_R[20])
library(dplyr)
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "binomial",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "loglin",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "lin",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "INVALID MODEL",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "NOT EXISTING COLUMN",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "amox",
col_date = "NOT EXISTING COLUMN",
info = TRUE))
# almost all E. coli are mero S in the Netherlands :)
expect_error(resistance_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "mero",
col_date = "date",
info = TRUE))
expect_error(portion_df(c("A", "B", "C")))
expect_error(portion_df(septic_patients[,"date"]))
})