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

(v0.7.1.9102) lintr

This commit is contained in:
2019-10-11 17:21:02 +02:00
parent 59af355a89
commit 00cdb498a0
65 changed files with 620 additions and 812 deletions

View File

@ -37,13 +37,13 @@ test_that("ab_property works", {
expect_identical(ab_name("Fluclox"), "Flucloxacillin")
expect_identical(ab_name("fluklox"), "Flucloxacillin")
expect_identical(ab_name("floxapen"), "Flucloxacillin")
expect_identical(ab_name(21319) , "Flucloxacillin")
expect_identical(ab_name(21319), "Flucloxacillin")
expect_identical(ab_name("J01CF05"), "Flucloxacillin")
expect_identical(ab_ddd("AMX", "oral"), 1)
expect_identical(ab_ddd("AMX", "oral", units = TRUE) , "g")
expect_identical(ab_ddd("AMX", "oral", units = TRUE), "g")
expect_identical(ab_ddd("AMX", "iv"), 1)
expect_identical(ab_ddd("AMX", "iv", units = TRUE) , "g")
expect_identical(ab_ddd("AMX", "iv", units = TRUE), "g")
expect_identical(ab_name(x = c("AMC", "PLB")), c("Amoxicillin/clavulanic acid", "Polymyxin B"))
expect_identical(ab_name(x = c("AMC", "PLB"), tolower = TRUE),

View File

@ -85,6 +85,6 @@ test_that("counts work", {
expect_error(count_S("test", as_percent = "test"))
expect_error(count_df(c("A", "B", "C")))
expect_error(count_df(example_isolates[,"date"]))
expect_error(count_df(example_isolates[, "date"]))
})

View File

@ -41,9 +41,8 @@ test_that("data sets are valid", {
# there should be no diacritics (i.e. non ASCII) characters in the datasets (CRAN policy)
datasets <- data(package = "AMR", envir = asNamespace("AMR"))$results[, "Item"]
for (i in 1:length(datasets)) {
for (i in seq_len(length(datasets))) {
dataset <- get(datasets[i], envir = asNamespace("AMR"))
#print(paste("testing data set", datasets[i]))
expect_identical(dataset_UTF8_to_ASCII(dataset), dataset)
}
})

View File

@ -33,16 +33,12 @@ test_that("first isolates work", {
na.rm = TRUE),
1317)
# first *weighted* isolates
# first weighted isolates
expect_equal(
suppressWarnings(
sum(
first_isolate(x = example_isolates %>% mutate(keyab = key_antibiotics(.)),
# let syntax determine these automatically:
# col_date = "date",
# col_patient_id = "patient_id",
# col_mo = "mo",
# col_keyantibiotics = "keyab",
# let syntax determine arguments automatically
type = "keyantibiotics",
info = TRUE),
na.rm = TRUE)),
@ -145,7 +141,7 @@ test_that("first isolates work", {
filter_specimen = "something_unexisting")))
# printing of exclusion message
expect_output(example_isolates %>%
expect_message(example_isolates %>%
first_isolate(col_date = "date",
col_mo = "mo",
col_patient_id = "patient_id",

View File

@ -34,4 +34,3 @@ test_that("frequency table works", {
library(dplyr)
expect_true(is.freq(example_isolates %>% freq(AMX)))
})

View File

@ -60,7 +60,7 @@ test_that("G-test works", {
y = c(780, 1560, 780),
rescale.p = TRUE))
expect_error(g.test(matrix(data = c(-1, -2, -3 , -4), ncol = 2, byrow = TRUE)))
expect_error(g.test(matrix(data = c(-1, -2, -3, -4), ncol = 2, byrow = TRUE)))
expect_error(g.test(matrix(data = c(0, 0, 0, 0), ncol = 2, byrow = TRUE)))
})

View File

@ -30,7 +30,6 @@ test_that("get_locale works", {
expect_identical(mo_fullname("CoNS", "nl"), "Coagulase-negatieve Staphylococcus (CNS)")
expect_identical(mo_fullname("CoNS", "es"), "Staphylococcus coagulasa negativo (SCN)")
expect_identical(mo_fullname("CoNS", "it"), "Staphylococcus negativo coagulasi (CoNS)")
# expect_identical(mo_fullname("CoNS", "fr"), "Staphylococcus \u00e0 coagulase n\u00e9gative (CoNS)")
expect_identical(mo_fullname("CoNS", "pt"), "Staphylococcus coagulase negativo (CoNS)")
})

View File

@ -30,35 +30,26 @@ test_that("ggplot_rsi works", {
# data should be equal
expect_equal(
(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi())$data %>%
summarise_all(portion_IR) %>% as.double(),
example_isolates %>% select(AMC, CIP) %>%
summarise_all(portion_IR) %>% as.double()
(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi())$data %>% summarise_all(portion_IR) %>% as.double(),
example_isolates %>% select(AMC, CIP) %>% summarise_all(portion_IR) %>% as.double()
)
print(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "interpretation", facet = "antibiotic"))
print(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))
expect_equal(
(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "interpretation", facet = "antibiotic"))$data %>%
summarise_all(portion_IR) %>% as.double(),
example_isolates %>% select(AMC, CIP) %>%
summarise_all(portion_IR) %>% as.double()
(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "interpretation", facet = "antibiotic"))$data %>% summarise_all(portion_IR) %>% as.double(),
example_isolates %>% select(AMC, CIP) %>% summarise_all(portion_IR) %>% as.double()
)
expect_equal(
(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>%
summarise_all(portion_IR) %>% as.double(),
example_isolates %>% select(AMC, CIP) %>%
summarise_all(portion_IR) %>% as.double()
(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>% summarise_all(portion_IR) %>% as.double(),
example_isolates %>% select(AMC, CIP) %>% summarise_all(portion_IR) %>% as.double()
)
expect_equal(
(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic",
facet = "interpretation"))$data %>%
summarise_all(count_IR) %>% as.double(),
example_isolates %>% select(AMC, CIP) %>%
summarise_all(count_IR) %>% as.double()
(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>% summarise_all(count_IR) %>% as.double(),
example_isolates %>% select(AMC, CIP) %>% summarise_all(count_IR) %>% as.double()
)
# support for scale_type ab and mo

View File

@ -32,11 +32,11 @@ test_that("mdro works", {
outcome <- mdro(example_isolates)
outcome <- eucast_exceptional_phenotypes(example_isolates, info = TRUE)
# check class
expect_equal(outcome %>% class(), c('ordered', 'factor'))
expect_equal(outcome %>% class(), c("ordered", "factor"))
outcome <- mdro(example_isolates, "nl", info = TRUE)
# check class
expect_equal(outcome %>% class(), c('ordered', 'factor'))
expect_equal(outcome %>% class(), c("ordered", "factor"))
# example_isolates should have these finding using Dutch guidelines
expect_equal(outcome %>% freq() %>% pull(count),

View File

@ -94,7 +94,7 @@ test_that("as.mo works", {
rep("B_STPHY_AURS", 9))
expect_identical(
as.character(
as.mo(c('EHEC', 'EPEC', 'EIEC', 'STEC', 'ATEC', 'UPEC'))),
as.mo(c("EHEC", "EPEC", "EIEC", "STEC", "ATEC", "UPEC"))),
rep("B_ESCHR_COLI", 6))
# unprevalent MO
expect_identical(
@ -114,13 +114,13 @@ test_that("as.mo works", {
c("UNKNOWN", NA_character_, "B_STNTR_MLTP", "B_KLBSL_PNMN_RHNS", "B_ESCHR_COLI"))
# check for Becker classification
expect_identical(as.character(as.mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPDR")
expect_identical(as.character(as.mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CONS")
expect_identical(as.character(as.mo("STAEPI", Becker = TRUE)), "B_STPHY_CONS")
expect_identical(as.character(as.mo("S. intermedius", Becker = FALSE)), "B_STPHY_INTR")
expect_identical(as.character(as.mo("Sta intermedius",Becker = FALSE)), "B_STPHY_INTR")
expect_identical(as.character(as.mo("Sta intermedius",Becker = TRUE)), "B_STPHY_COPS")
expect_identical(as.character(as.mo("STAINT", Becker = TRUE)), "B_STPHY_COPS")
expect_identical(as.character(as.mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPDR")
expect_identical(as.character(as.mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CONS")
expect_identical(as.character(as.mo("STAEPI", Becker = TRUE)), "B_STPHY_CONS")
expect_identical(as.character(as.mo("S. intermedius", Becker = FALSE)), "B_STPHY_INTR")
expect_identical(as.character(as.mo("Sta intermedius", Becker = FALSE)), "B_STPHY_INTR")
expect_identical(as.character(as.mo("Sta intermedius", Becker = TRUE)), "B_STPHY_COPS")
expect_identical(as.character(as.mo("STAINT", Becker = TRUE)), "B_STPHY_COPS")
# aureus must only be influenced if Becker = "all"
expect_identical(as.character(as.mo("STAAUR", Becker = FALSE)), "B_STPHY_AURS")
expect_identical(as.character(as.mo("STAAUR", Becker = TRUE)), "B_STPHY_AURS")
@ -150,7 +150,7 @@ test_that("as.mo works", {
# select with one column
expect_identical(
example_isolates[1:10,] %>%
example_isolates[1:10, ] %>%
left_join_microorganisms() %>%
select(genus) %>%
as.mo() %>%
@ -160,9 +160,9 @@ test_that("as.mo works", {
# select with two columns
expect_identical(
example_isolates[1:10,] %>%
example_isolates[1:10, ] %>%
pull(mo),
example_isolates[1:10,] %>%
example_isolates[1:10, ] %>%
left_join_microorganisms() %>%
select(genus, species) %>%
as.mo())
@ -260,10 +260,6 @@ test_that("as.mo works", {
expect_null(mo_failures())
expect_true(example_isolates %>% pull(mo) %>% is.mo())
# expect_equal(get_mo_code("test", "mo"), "test")
# expect_equal(length(get_mo_code("Escherichia", "genus")),
# nrow(AMR::microorganisms[base::which(AMR::microorganisms[, "genus"] %in% "Escherichia"),]))
expect_error(translate_allow_uncertain(5))
# very old MO codes (<= v0.5.0)

View File

@ -57,7 +57,7 @@ test_that("mo_property works", {
expect_equal(mo_shortname("Streptococcus agalactiae"), "S. agalactiae")
expect_equal(mo_shortname("Streptococcus agalactiae", Lancefield = TRUE), "GBS")
#expect_true(mo_url("Escherichia coli") %like% "www.catalogueoflife.org")
expect_true(mo_url("Escherichia coli") %like% "www.catalogueoflife.org")
# test integrity
MOs <- AMR::microorganisms

View File

@ -117,5 +117,5 @@ test_that("portions works", {
)
expect_error(portion_df(c("A", "B", "C")))
expect_error(portion_df(example_isolates[,"date"]))
expect_error(portion_df(example_isolates[, "date"]))
})