1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 13:01:59 +02:00

23 Commits

Author SHA1 Message Date
70a07bad39 (v1.8.1.9010) random when pkg not loaded 2022-05-16 12:52:50 +02:00
2c5bc73ed6 (v1.8.1.9009) random when pkg not loaded 2022-05-16 09:29:46 +02:00
58ed15e7ac (v1.8.1.9008) website update 2022-05-11 10:26:58 +02:00
6de5375256 (v1.8.1.9007) website update 2022-05-11 10:10:31 +02:00
859224e9d0 (v1.8.1.9006) added EUCAST 2022 and CLSI 2022 2022-05-10 21:34:30 +02:00
680e8e7a41 (v1.8.1.9005) as.rsi() fix for EUCAST 2022-05-10 17:01:37 +02:00
d4e22069bc (v1.8.1.9004) fix for table() on MICs 2022-05-09 21:33:27 +02:00
1c891cc90c (v1.8.1.9003) set_mo_source() fix 2022-05-09 20:36:44 +02:00
152db9d1b5 (v1.8.1.9002) fix for table() on MICs 2022-05-09 17:08:40 +02:00
4754848e96 (v1.8.1.9001) update unit tests, fixes #53 2022-04-08 11:02:45 +02:00
641b88c814 website update 2022-03-27 09:37:55 +02:00
ccb09706e4 v1.8.1 2022-03-24 23:05:04 +01:00
7b0f1596bd (v1.8.0.9010) as.mo improvement 2022-03-15 17:35:02 +01:00
0fb9a1b194 prerelease 1.8.1 2022-03-14 16:43:15 +01:00
45e9546538 prerelease 1.8.1
Merge branch 'development' of https://github.com/msberends/AMR into development

# Conflicts:
#	docs/articles/AMR.html
#	docs/articles/AMR_files/figure-html/disk_plots-1.png
#	docs/articles/AMR_files/figure-html/disk_plots_mo_ab-1.png
#	docs/articles/AMR_files/figure-html/mic_plots-1.png
#	docs/articles/AMR_files/figure-html/mic_plots-2.png
#	docs/articles/AMR_files/figure-html/mic_plots_mo_ab-1.png
#	docs/articles/AMR_files/figure-html/mic_plots_mo_ab-2.png
#	docs/articles/AMR_files/figure-html/plot 1-1.png
#	docs/articles/AMR_files/figure-html/plot 3-1.png
#	docs/articles/AMR_files/figure-html/plot 4-1.png
#	docs/articles/AMR_files/figure-html/plot 5-1.png
#	docs/articles/EUCAST.html
#	docs/articles/MDR.html
#	docs/articles/PCA.html
#	docs/articles/PCA_files/figure-html/unnamed-chunk-6-1.png
#	docs/articles/PCA_files/figure-html/unnamed-chunk-7-1.png
#	docs/articles/SPSS.html
#	docs/articles/WHONET.html
#	docs/articles/WHONET_files/figure-html/unnamed-chunk-7-1.png
#	docs/articles/benchmarks.html
#	docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png
#	docs/articles/datasets.html
#	docs/articles/resistance_predict.html
#	docs/articles/resistance_predict_files/figure-html/unnamed-chunk-4-1.png
#	docs/articles/resistance_predict_files/figure-html/unnamed-chunk-5-1.png
#	docs/articles/resistance_predict_files/figure-html/unnamed-chunk-5-2.png
#	docs/articles/resistance_predict_files/figure-html/unnamed-chunk-6-1.png
#	docs/articles/resistance_predict_files/figure-html/unnamed-chunk-7-1.png
#	docs/articles/welcome_to_AMR.html
#	docs/news/index.html
#	docs/pkgdown.yml
#	docs/reference/AMR-deprecated.html
#	docs/reference/AMR.html
#	docs/reference/WHOCC.html
#	docs/reference/WHONET.html
#	docs/reference/antibiotics.html
#	docs/reference/catalogue_of_life.html
#	docs/reference/catalogue_of_life_version.html
#	docs/reference/dosage.html
#	docs/reference/example_isolates.html
#	docs/reference/example_isolates_unclean.html
#	docs/reference/g.test.html
#	docs/reference/intrinsic_resistant.html
#	docs/reference/microorganisms.codes.html
#	docs/reference/microorganisms.html
#	docs/reference/microorganisms.old.html
#	docs/reference/rsi_translation.html
2022-03-14 16:37:37 +01:00
1b0983e382 (v1.8.1) prerelease 1.8.1 2022-03-14 16:36:10 +01:00
8c9feea087 website update 2022-03-12 19:53:29 +01:00
08d387b5ce (v1.8.0.9005) as.rsi() fix 2022-03-10 19:33:25 +01:00
ad82bb4ce0 (v1.8.0.9004) MIC printing in tibbles 2022-03-03 21:11:02 +01:00
dedbe92322 (v1.8.0.9003) deps update 2022-03-02 23:16:37 +01:00
3b2b2be5f8 (v1.8.0.9002) as.rsi() cleanup, more informative warnings 2022-03-02 15:38:55 +01:00
18e8525d10 (v1.8.0.9001) as.mo improvement, fixes #52 2022-02-26 21:58:23 +01:00
be792cc9eb (v1.8.0.9000) unit tests for R 3.3 2022-02-01 17:08:10 +01:00
230 changed files with 23579 additions and 22606 deletions

View File

@ -33,3 +33,4 @@
^vignettes/SPSS.Rmd$ ^vignettes/SPSS.Rmd$
^vignettes/WHONET.Rmd$ ^vignettes/WHONET.Rmd$
^logo.svg$ ^logo.svg$
^CRAN-SUBMISSION$

View File

@ -57,8 +57,8 @@ jobs:
- {os: macOS-latest, r: '3.6', allowfail: false} - {os: macOS-latest, r: '3.6', allowfail: false}
- {os: macOS-latest, r: '3.5', allowfail: false} - {os: macOS-latest, r: '3.5', allowfail: false}
- {os: macOS-latest, r: '3.4', allowfail: false} - {os: macOS-latest, r: '3.4', allowfail: false}
- {os: macOS-latest, r: '3.3', allowfail: false} # - {os: macOS-latest, r: '3.3', allowfail: false}
- {os: macOS-latest, r: '3.2', allowfail: false} # - {os: macOS-latest, r: '3.2', allowfail: false}
# - {os: macOS-latest, r: '3.1', allowfail: true} # - {os: macOS-latest, r: '3.1', allowfail: true}
# - {os: macOS-latest, r: '3.0', allowfail: true} # - {os: macOS-latest, r: '3.0', allowfail: true}
- {os: ubuntu-20.04, r: 'devel', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: 'devel', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
@ -77,7 +77,7 @@ jobs:
- {os: windows-latest, r: '3.6', allowfail: false} - {os: windows-latest, r: '3.6', allowfail: false}
- {os: windows-latest, r: '3.5', allowfail: false} - {os: windows-latest, r: '3.5', allowfail: false}
- {os: windows-latest, r: '3.4', allowfail: false} - {os: windows-latest, r: '3.4', allowfail: false}
- {os: windows-latest, r: '3.3', allowfail: false} # - {os: windows-latest, r: '3.3', allowfail: false}
# - {os: windows-latest, r: '3.2', allowfail: true} # - {os: windows-latest, r: '3.2', allowfail: true}
# - {os: windows-latest, r: '3.1', allowfail: true} # - {os: windows-latest, r: '3.1', allowfail: true}
# - {os: windows-latest, r: '3.0', allowfail: true} # - {os: windows-latest, r: '3.0', allowfail: true}

3
CRAN-SUBMISSION Normal file
View File

@ -0,0 +1,3 @@
Version: 1.8.1
Date: 2022-03-16 18:22:51 UTC
SHA: 7b0f1596bd65fbb72681a7e3a6a7e4e469a891e8

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.8.0 Version: 1.8.1.9010
Date: 2022-01-03 Date: 2022-05-16
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR) Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by data analysis and to work with microbial and antimicrobial properties by
@ -9,7 +9,7 @@ Description: Functions to simplify and standardise antimicrobial resistance (AMR
Authors@R: c( Authors@R: c(
person(given = c("Matthijs", "S."), person(given = c("Matthijs", "S."),
family = "Berends", family = "Berends",
email = "m.s.berends@umcg.nl", email = "m.berends@certe.nl",
role = c("aut", "cre"), role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-7620-1800")), comment = c(ORCID = "0000-0001-7620-1800")),
person(given = c("Christian", "F."), person(given = c("Christian", "F."),
@ -71,7 +71,8 @@ Depends: R (>= 3.0.0)
Enhances: Enhances:
cleaner, cleaner,
skimr, skimr,
ggplot2 ggplot2,
tidyselect
Suggests: Suggests:
curl, curl,
dplyr, dplyr,

View File

@ -50,7 +50,6 @@ S3method(any,mic)
S3method(as.data.frame,ab) S3method(as.data.frame,ab)
S3method(as.data.frame,mo) S3method(as.data.frame,mo)
S3method(as.double,mic) S3method(as.double,mic)
S3method(as.integer,mic)
S3method(as.list,custom_eucast_rules) S3method(as.list,custom_eucast_rules)
S3method(as.list,custom_mdro_guideline) S3method(as.list,custom_mdro_guideline)
S3method(as.matrix,mic) S3method(as.matrix,mic)

42
NEWS.md
View File

@ -1,8 +1,40 @@
# `AMR` 1.8.1.9010
## <small>Last updated: 16 May 2022</small>
### 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.
### Changed
* Fix for `as.rsi()` on certain EUCAST breakpoints for MIC values
* Removed `as.integer()` for MIC values, since MIC are not integer values and running `table()` on MIC values consequently failed for not being able to retrieve the level position (as that's how normally `as.integer()` on `factor`s work)
* `droplevels()` on MIC will now return a common `factor` at default and will lose the `<mic>` class. Use `droplevels(..., as.mic = TRUE)` to keep the `<mic>` class.
* Small fix for using `ab_from_text()`
* Fixes for reading in text files using `set_mo_source()`, which now also allows the source file to contain valid taxonomic names instead of only valid microorganism ID of this package
* Using any `random_*()` function (such as `random_mic()`) is now possible by directly calling the package without loading it first: `AMR::random_mic(10)`
# `AMR` 1.8.1
### Changed
* Fix for using `as.rsi()` on values containing capped values (such as `>=`), sometimes leading to `NA`
* Support for antibiotic interpretations of the MIPS laboratory system: `"U"` for S ('susceptible urine'), `"D"` for I ('susceptible dose-dependent')
* Improved algorithm of `as.mo()`, especially for ignoring non-taxonomic text, such as:
```r
mo_name("methicillin-resistant S. aureus (MRSA)")
#> [1] "Staphylococcus aureus"
```
* More informative warning messages
* Added 192 as valid MIC
* Updated MIC printing in tibbles
* Increased speed for loading the package
### Other
* Fix for unit testing on R 3.3
* Fix for size of some image elements, as requested by CRAN
# `AMR` 1.8.0 # `AMR` 1.8.0
All functions in this package are now all considered to be stable. Updates to the AMR interpretation rules (such as by EUCAST and CLSI), the microbial taxonomy, and the antibiotic dosages will all be updated every 6 to 12 months from now on.
### Breaking changes ### Breaking changes
* Removed `p_symbol()` and all `filter_*()` functions (except for `filter_first_isolate()`), which were all deprecated in a previous package version * Removed `p_symbol()` and all `filter_*()` functions (except for `filter_first_isolate()`), which were all deprecated in a previous package version
* Removed the `key_antibiotics()` and `key_antibiotics_equal()` functions, which were deprecated and superseded by `key_antimicrobials()` and `antimicrobials_equal()` * Removed the `key_antibiotics()` and `key_antibiotics_equal()` functions, which were deprecated and superseded by `key_antimicrobials()` and `antimicrobials_equal()`
@ -256,7 +288,7 @@ All functions in this package are now all considered to be stable. Updates to th
filter(is_new_episode(date, episode_days = 60)) filter(is_new_episode(date, episode_days = 60))
``` ```
* Functions `mo_is_gram_negative()` and `mo_is_gram_positive()` as wrappers around `mo_gramstain()`. They always return `TRUE` or `FALSE` (except when the input is `NA` or the MO code is `UNKNOWN`), thus always return `FALSE` for species outside the taxonomic kingdom of Bacteria. * Functions `mo_is_gram_negative()` and `mo_is_gram_positive()` as wrappers around `mo_gramstain()`. They always return `TRUE` or `FALSE` (except when the input is `NA` or the MO code is `UNKNOWN`), thus always return `FALSE` for species outside the taxonomic kingdom of Bacteria.
* Function `mo_is_intrinsic_resistant()` to test for intrinsic resistance, based on [EUCAST Intrinsic Resistance and Unusual Phenotypes v3.2](https://www.eucast.org/expert_rules_and_intrinsic_resistance/) from 2020. * Function `mo_is_intrinsic_resistant()` to test for intrinsic resistance, based on EUCAST Intrinsic Resistance and Unusual Phenotypes v3.2 from 2020.
* Functions `random_mic()`, `random_disk()` and `random_rsi()` for random value generation. The functions `random_mic()` and `random_disk()` take microorganism names and antibiotic names as input to make generation more realistic. * Functions `random_mic()`, `random_disk()` and `random_rsi()` for random value generation. The functions `random_mic()` and `random_disk()` take microorganism names and antibiotic names as input to make generation more realistic.
### Changed ### Changed
@ -1352,7 +1384,7 @@ We've got a new website: [https://msberends.gitlab.io/AMR](https://msberends.git
* Function `guess_atc` to **determine the ATC** of an antibiotic based on name, trade name, or known abbreviations * Function `guess_atc` to **determine the ATC** of an antibiotic based on name, trade name, or known abbreviations
* Function `freq` to create **frequency tables**, with additional info in a header * Function `freq` to create **frequency tables**, with additional info in a header
* Function `MDRO` to **determine Multi Drug Resistant Organisms (MDRO)** with support for country-specific guidelines. * Function `MDRO` to **determine Multi Drug Resistant Organisms (MDRO)** with support for country-specific guidelines.
* [Exceptional resistances defined by EUCAST](https://www.eucast.org/expert_rules_and_intrinsic_resistance/) are also supported instead of countries alone * Exceptional resistances defined by EUCAST are also supported instead of countries alone
* Functions `BRMO` and `MRGN` are wrappers for Dutch and German guidelines, respectively * Functions `BRMO` and `MRGN` are wrappers for Dutch and German guidelines, respectively
* New algorithm to determine weighted isolates, can now be `"points"` or `"keyantibiotics"`, see `?first_isolate` * New algorithm to determine weighted isolates, can now be `"points"` or `"keyantibiotics"`, see `?first_isolate`
* New print format for `tibble`s and `data.table`s * New print format for `tibble`s and `data.table`s

View File

@ -36,15 +36,15 @@ EUCAST_VERSION_BREAKPOINTS <- list("11.0" = list(version_txt = "v11.0",
EUCAST_VERSION_EXPERT_RULES <- list("3.1" = list(version_txt = "v3.1", EUCAST_VERSION_EXPERT_RULES <- list("3.1" = list(version_txt = "v3.1",
year = 2016, year = 2016,
title = "'EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes'", title = "'EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes'",
url = "https://www.eucast.org/expert_rules_and_intrinsic_resistance/"), url = "https://www.eucast.org/expert_rules_and_expected_phenotypes/"),
"3.2" = list(version_txt = "v3.2", "3.2" = list(version_txt = "v3.2",
year = 2020, year = 2020,
title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'", title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'",
url = "https://www.eucast.org/expert_rules_and_intrinsic_resistance/"), url = "https://www.eucast.org/expert_rules_and_expected_phenotypes/"),
"3.3" = list(version_txt = "v3.3", "3.3" = list(version_txt = "v3.3",
year = 2021, year = 2021,
title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'", title = "'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes'",
url = "https://www.eucast.org/expert_rules_and_intrinsic_resistance/")) url = "https://www.eucast.org/expert_rules_and_expected_phenotypes/"))
SNOMED_VERSION <- list(title = "Public Health Information Network Vocabulary Access and Distribution System (PHIN VADS)", SNOMED_VERSION <- list(title = "Public Health Information Network Vocabulary Access and Distribution System (PHIN VADS)",
current_source = "US Edition of SNOMED CT from 1 September 2020", current_source = "US Edition of SNOMED CT from 1 September 2020",

View File

@ -206,7 +206,7 @@ check_dataset_integrity <- function() {
" overwritten by your global environment and prevent", plural[2], " overwritten by your global environment and prevent", plural[2],
" the AMR package from working correctly: ", " the AMR package from working correctly: ",
vector_and(overwritten, quotes = "'"), vector_and(overwritten, quotes = "'"),
".\nPlease rename your object", plural[3], ".", call = FALSE) ".\nPlease rename your object", plural[3], ".")
} }
} }
# check if other packages did not overwrite our data sets # check if other packages did not overwrite our data sets
@ -492,7 +492,7 @@ message_ <- function(...,
warning_ <- function(..., warning_ <- function(...,
add_fn = list(), add_fn = list(),
immediate = FALSE, immediate = FALSE,
call = TRUE) { call = FALSE) {
warning(word_wrap(..., warning(word_wrap(...,
add_fn = add_fn, add_fn = add_fn,
as_note = FALSE), as_note = FALSE),
@ -559,7 +559,7 @@ stop_ifnot <- function(expr, ..., call = TRUE) {
return_after_integrity_check <- function(value, type, check_vector) { return_after_integrity_check <- function(value, type, check_vector) {
if (!all(value[!is.na(value)] %in% check_vector)) { if (!all(value[!is.na(value)] %in% check_vector)) {
warning_(paste0("invalid ", type, ", NA generated"), call = FALSE) warning_(paste0("invalid ", type, ", NA generated"))
value[!value %in% check_vector] <- NA value[!value %in% check_vector] <- NA
} }
value value
@ -638,7 +638,7 @@ vector_or <- function(v, quotes = TRUE, reverse = FALSE, sort = TRUE, initial_ca
if (isTRUE(initial_captital)) { if (isTRUE(initial_captital)) {
v[1] <- gsub("^([a-z])", "\\U\\1", v[1], perl = TRUE) v[1] <- gsub("^([a-z])", "\\U\\1", v[1], perl = TRUE)
} }
if (length(v) == 1) { if (length(v) <= 1) {
return(paste0(quotes, v, quotes)) return(paste0(quotes, v, quotes))
} }
if (identical(v, c("I", "R", "S"))) { if (identical(v, c("I", "R", "S"))) {

10
R/ab.R
View File

@ -455,15 +455,13 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
x_unknown_ATCs <- x_unknown[x_unknown %like% "[A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9]"] x_unknown_ATCs <- x_unknown[x_unknown %like% "[A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9]"]
x_unknown <- x_unknown[!x_unknown %in% x_unknown_ATCs] x_unknown <- x_unknown[!x_unknown %in% x_unknown_ATCs]
if (length(x_unknown_ATCs) > 0 & fast_mode == FALSE) { if (length(x_unknown_ATCs) > 0 & fast_mode == FALSE) {
warning_("These ATC codes are not (yet) in the antibiotics data set: ", warning_("in `as.ab()`: these ATC codes are not (yet) in the antibiotics data set: ",
vector_and(x_unknown_ATCs), ".", vector_and(x_unknown_ATCs), ".")
call = FALSE)
} }
if (length(x_unknown) > 0 & fast_mode == FALSE) { if (length(x_unknown) > 0 & fast_mode == FALSE) {
warning_("These values could not be coerced to a valid antimicrobial ID: ", warning_("in `as.ab()`: these values could not be coerced to a valid antimicrobial ID: ",
vector_and(x_unknown), ".", vector_and(x_unknown), ".")
call = FALSE)
} }
x_result <- x_new[match(x_bak_clean, x)] x_result <- x_new[match(x_bak_clean, x)]

View File

@ -240,8 +240,8 @@ ab_ddd <- function(x, administration = "oral", ...) {
units <- list(...)$units units <- list(...)$units
if (!is.null(units) && isTRUE(units)) { if (!is.null(units) && isTRUE(units)) {
if (message_not_thrown_before("ab_ddd", entire_session = TRUE)) { if (message_not_thrown_before("ab_ddd", entire_session = TRUE)) {
warning_("Using `ab_ddd(..., units = TRUE)` is deprecated, use `ab_ddd_units()` to retrieve units instead. ", 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.", call = FALSE) "This warning will be shown once per session.")
} }
ddd_prop <- paste0(ddd_prop, "_units") ddd_prop <- paste0(ddd_prop, "_units")
} else { } else {
@ -250,9 +250,9 @@ ab_ddd <- function(x, administration = "oral", ...) {
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))) {
warning_("DDDs of some combined products are available for different dose combinations and not (yet) part of the AMR package. ", warning_("in `ab_ddd()`: DDDs of some 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/", call = FALSE) "www.whocc.no/ddd/list_of_ddds_combined_products/")
} }
out out
} }
@ -265,9 +265,9 @@ ab_ddd_units <- function(x, administration = "oral", ...) {
x <- as.ab(x, ...) x <- as.ab(x, ...)
if (any(ab_name(x, language = NULL) %like% "/")) { if (any(ab_name(x, language = NULL) %like% "/")) {
warning_("DDDs of combined products are available for different dose combinations and not (yet) part of the AMR package. ", warning_("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/", call = FALSE) "www.whocc.no/ddd/list_of_ddds_combined_products/")
} }
ddd_prop <- paste0(administration, "_units") ddd_prop <- paste0(administration, "_units")
@ -311,12 +311,12 @@ ab_url <- function(x, open = FALSE, ...) {
NAs <- ab_name(ab, tolower = TRUE, language = NULL)[!is.na(ab) & is.na(atcs)] NAs <- ab_name(ab, tolower = TRUE, language = NULL)[!is.na(ab) & is.na(atcs)]
if (length(NAs) > 0) { if (length(NAs) > 0) {
warning_("No ATC code available for ", vector_and(NAs, quotes = FALSE), ".") warning_("in `ab_url()`: no ATC code available for ", vector_and(NAs, quotes = FALSE), ".")
} }
if (open == TRUE) { if (open == TRUE) {
if (length(u) > 1 & !is.na(u[1L])) { if (length(u) > 1 & !is.na(u[1L])) {
warning_("Only the first URL will be opened, as `browseURL()` only suports one string.") warning_("in `ab_url()`: only the first URL will be opened, as `browseURL()` only suports one string.")
} }
if (!is.na(u[1L])) { if (!is.na(u[1L])) {
utils::browseURL(u[1L]) utils::browseURL(u[1L])
@ -385,7 +385,8 @@ set_ab_names <- function(data, ..., property = "name", language = get_AMR_locale
}, },
USE.NAMES = FALSE) USE.NAMES = FALSE)
if (any(x %in% c("", NA))) { if (any(x %in% c("", NA))) {
warning_("No ", property, " found for column(s): ", vector_and(vars[x %in% c("", NA)], sort = FALSE), call = FALSE) warning_("in `set_ab_names()`: no ", property, " found for column(s): ",
vector_and(vars[x %in% c("", NA)], sort = FALSE))
x[x %in% c("", NA)] <- vars[x %in% c("", NA)] x[x %in% c("", NA)] <- vars[x %in% c("", NA)]
} }

View File

@ -481,14 +481,13 @@ ab_select_exec <- function(function_name,
untreatable <- antibiotics[which(antibiotics$name %like% "-high|EDTA|polysorbate|macromethod|screening|/nacubactam"), "ab", drop = TRUE] untreatable <- antibiotics[which(antibiotics$name %like% "-high|EDTA|polysorbate|macromethod|screening|/nacubactam"), "ab", drop = TRUE]
if (any(untreatable %in% names(ab_in_data))) { if (any(untreatable %in% names(ab_in_data))) {
if (message_not_thrown_before(function_name, "ab_class", "untreatable", entire_session = TRUE)) { if (message_not_thrown_before(function_name, "ab_class", "untreatable", entire_session = TRUE)) {
warning_("Some agents in `", function_name, "()` were ignored since they cannot be used for treating patients: ", warning_("in `", function_name, "()`: some agents were ignored since they cannot be used for treating patients: ",
vector_and(ab_name(names(ab_in_data)[names(ab_in_data) %in% untreatable], vector_and(ab_name(names(ab_in_data)[names(ab_in_data) %in% untreatable],
language = NULL, language = NULL,
tolower = TRUE), tolower = TRUE),
quotes = FALSE, quotes = FALSE,
sort = TRUE), ". They can be included using `", function_name, "(only_treatable = FALSE)`. ", sort = TRUE), ". They can be included using `", function_name, "(only_treatable = FALSE)`. ",
"This warning will be shown once per session.", "This warning will be shown once per session.")
call = FALSE)
} }
ab_in_data <- ab_in_data[!names(ab_in_data) %in% untreatable] ab_in_data <- ab_in_data[!names(ab_in_data) %in% untreatable]
} }

View File

@ -95,10 +95,10 @@ age <- function(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE, ...) {
if (any(ages < 0, na.rm = TRUE)) { if (any(ages < 0, na.rm = TRUE)) {
ages[!is.na(ages) & ages < 0] <- NA ages[!is.na(ages) & ages < 0] <- NA
warning_("NAs introduced for ages below 0.", call = TRUE) warning_("in `age()`: NAs introduced for ages below 0.")
} }
if (any(ages > 120, na.rm = TRUE)) { if (any(ages > 120, na.rm = TRUE)) {
warning_("Some ages are above 120.", call = TRUE) warning_("in `age()`: some ages are above 120.")
} }
if (isTRUE(na.rm)) { if (isTRUE(na.rm)) {
@ -171,7 +171,7 @@ age_groups <- function(x, split_at = c(12, 25, 55, 75), na.rm = FALSE) {
if (any(x < 0, na.rm = TRUE)) { if (any(x < 0, na.rm = TRUE)) {
x[x < 0] <- NA x[x < 0] <- NA
warning_("NAs introduced for ages below 0.", call = TRUE) warning_("in `age_groups()`: NAs introduced for ages below 0.")
} }
if (is.character(split_at)) { if (is.character(split_at)) {
split_at <- split_at[1L] split_at <- split_at[1L]

View File

@ -175,7 +175,7 @@ atc_online_property <- function(atc_code,
colnames(out) <- gsub("^atc.*", "atc", tolower(colnames(out))) colnames(out) <- gsub("^atc.*", "atc", tolower(colnames(out)))
if (length(out) == 0) { if (length(out) == 0) {
warning_("ATC not found: ", atc_code[i], ". Please check ", atc_url, ".", call = FALSE) warning_("in `atc_online_property()`: ATC not found: ", atc_code[i], ". Please check ", atc_url, ".")
returnvalue[i] <- NA returnvalue[i] <- NA
next next
} }

View File

@ -184,7 +184,7 @@ format.bug_drug_combinations <- function(x,
if (inherits(x, "grouped")) { if (inherits(x, "grouped")) {
# bug_drug_combinations() has been run on groups, so de-group here # bug_drug_combinations() has been run on groups, so de-group here
warning_("formatting the output of `bug_drug_combinations()` does not support grouped variables, they are ignored", call = FALSE) warning_("in `format()`: formatting the output of `bug_drug_combinations()` does not support grouped variables, they were ignored")
idx <- split(seq_len(nrow(x)), paste0(x$mo, "%%", x$ab)) idx <- split(seq_len(nrow(x)), paste0(x$mo, "%%", x$ab))
x <- data.frame(mo = gsub("(.*)%%(.*)", "\\1", names(idx)), x <- data.frame(mo = gsub("(.*)%%(.*)", "\\1", names(idx)),
ab = gsub("(.*)%%(.*)", "\\2", names(idx)), ab = gsub("(.*)%%(.*)", "\\2", names(idx)),

View File

@ -43,7 +43,7 @@ format_included_data_number <- function(data) {
#' #'
#' This package contains the complete taxonomic tree (last updated: `r CATALOGUE_OF_LIFE$yearmonth_LPSN`) of almost all microorganisms from the authoritative and comprehensive Catalogue of Life (CoL), supplemented with data from the List of Prokaryotic names with Standing in Nomenclature (LPSN). #' This package contains the complete taxonomic tree (last updated: `r CATALOGUE_OF_LIFE$yearmonth_LPSN`) of almost all microorganisms from the authoritative and comprehensive Catalogue of Life (CoL), supplemented with data from the List of Prokaryotic names with Standing in Nomenclature (LPSN).
#' @section Catalogue of Life: #' @section Catalogue of Life:
#' \if{html}{\figure{logo_col.png}{options: height=40px style=margin-bottom:5px} \cr} #' \if{html}{\figure{logo_col.png}{options: height="40" style=margin-bottom:"5"} \cr}
#' This package contains the complete taxonomic tree of almost all microorganisms (`r format_included_data_number(microorganisms)` species) from the authoritative and comprehensive Catalogue of Life (CoL, <http://www.catalogueoflife.org>). The CoL is the most comprehensive and authoritative global index of species currently available. Nonetheless, we supplemented the CoL data with data from the List of Prokaryotic names with Standing in Nomenclature (LPSN, [lpsn.dsmz.de](https://lpsn.dsmz.de)). This supplementation is needed until the [CoL+ project](https://github.com/CatalogueOfLife/general) is finished, which we await. #' This package contains the complete taxonomic tree of almost all microorganisms (`r format_included_data_number(microorganisms)` species) from the authoritative and comprehensive Catalogue of Life (CoL, <http://www.catalogueoflife.org>). The CoL is the most comprehensive and authoritative global index of species currently available. Nonetheless, we supplemented the CoL data with data from the List of Prokaryotic names with Standing in Nomenclature (LPSN, [lpsn.dsmz.de](https://lpsn.dsmz.de)). This supplementation is needed until the [CoL+ project](https://github.com/CatalogueOfLife/general) is finished, which we await.
#' #'
#' [Click here][catalogue_of_life] for more information about the included taxa. Check which versions of the CoL and LPSN were included in this package with [catalogue_of_life_version()]. #' [Click here][catalogue_of_life] for more information about the included taxa. Check which versions of the CoL and LPSN were included in this package with [catalogue_of_life_version()].

View File

@ -251,7 +251,14 @@
#' - `breakpoint_S`\cr Lowest MIC value or highest number of millimetres that leads to "S" #' - `breakpoint_S`\cr Lowest MIC value or highest number of millimetres that leads to "S"
#' - `breakpoint_R`\cr Highest MIC value or lowest number of millimetres that leads to "R" #' - `breakpoint_R`\cr Highest MIC value or lowest number of millimetres that leads to "R"
#' - `uti`\cr A [logical] value (`TRUE`/`FALSE`) to indicate whether the rule applies to a urinary tract infection (UTI) #' - `uti`\cr A [logical] value (`TRUE`/`FALSE`) to indicate whether the rule applies to a urinary tract infection (UTI)
#' @details The repository of this `AMR` package contains a file comprising this exact data set: <https://github.com/msberends/AMR/blob/main/data-raw/rsi_translation.txt>. This file **allows for machine reading EUCAST and CLSI guidelines**, which is almost impossible with the Excel and PDF files distributed by EUCAST and CLSI. The file is updated automatically and the `mo` and `ab` columns have been transformed to contain the full official names instead of codes. #' @details
#' Overview of the data set:
#'
#' ```{r}
#' head(rsi_translation)
#' ```
#'
#' The repository of this `AMR` package contains a file comprising this exact data set: <https://github.com/msberends/AMR/blob/main/data-raw/rsi_translation.txt>. This file **allows for machine reading EUCAST and CLSI guidelines**, which is almost impossible with the Excel and PDF files distributed by EUCAST and CLSI. The file is updated automatically and the `mo` and `ab` columns have been transformed to contain the full official names instead of codes.
#' @inheritSection AMR Reference Data Publicly Available #' @inheritSection AMR Reference Data Publicly Available
#' @inheritSection AMR Read more on Our Website! #' @inheritSection AMR Read more on Our Website!
#' @seealso [intrinsic_resistant] #' @seealso [intrinsic_resistant]

View File

@ -100,10 +100,10 @@ as.disk <- function(x, na.rm = FALSE) {
unique() %pm>% unique() %pm>%
sort() %pm>% sort() %pm>%
vector_and(quotes = TRUE) vector_and(quotes = TRUE)
warning_(na_after - na_before, " results truncated (", warning_("in `as.disk()`: ", na_after - na_before, " results truncated (",
round(((na_after - na_before) / length(x)) * 100), round(((na_after - na_before) / length(x)) * 100),
"%) that were invalid disk zones: ", "%) that were invalid disk zones: ",
list_missing, call = FALSE) list_missing)
} }
} }
set_clean_class(as.integer(x), set_clean_class(as.integer(x),

View File

@ -181,8 +181,7 @@ eucast_rules <- function(x,
meet_criteria(custom_rules, allow_class = "custom_eucast_rules", allow_NULL = TRUE) meet_criteria(custom_rules, allow_class = "custom_eucast_rules", allow_NULL = TRUE)
if ("custom" %in% rules & is.null(custom_rules)) { if ("custom" %in% rules & is.null(custom_rules)) {
warning_("No custom rules were set with the `custom_rules` argument", warning_("in `eucast_rules()`: no custom rules were set with the `custom_rules` argument",
call = FALSE,
immediate = TRUE) immediate = TRUE)
rules <- rules[rules != "custom"] rules <- rules[rules != "custom"]
if (length(rules) == 0) { if (length(rules) == 0) {
@ -915,13 +914,12 @@ eucast_rules <- function(x,
# take order from original data set # take order from original data set
warn_lacking_rsi_class <- warn_lacking_rsi_class[order(colnames(x.bak))] warn_lacking_rsi_class <- warn_lacking_rsi_class[order(colnames(x.bak))]
warn_lacking_rsi_class <- warn_lacking_rsi_class[!is.na(warn_lacking_rsi_class)] warn_lacking_rsi_class <- warn_lacking_rsi_class[!is.na(warn_lacking_rsi_class)]
warning_("Not all columns with antimicrobial results are of class <rsi>. Transform them on beforehand, with e.g.:\n", warning_("in `eucast_rules()`: not all columns with antimicrobial results are of class <rsi>. Transform them on beforehand, with e.g.:\n",
" - ", x_deparsed, " %>% as.rsi(", ifelse(length(warn_lacking_rsi_class) == 1, " - ", x_deparsed, " %>% as.rsi(", ifelse(length(warn_lacking_rsi_class) == 1,
warn_lacking_rsi_class, warn_lacking_rsi_class,
paste0(warn_lacking_rsi_class[1], ":", warn_lacking_rsi_class[length(warn_lacking_rsi_class)])), ")\n", paste0(warn_lacking_rsi_class[1], ":", warn_lacking_rsi_class[length(warn_lacking_rsi_class)])), ")\n",
" - ", x_deparsed, " %>% mutate_if(is.rsi.eligible, as.rsi)\n", " - ", x_deparsed, " %>% mutate_if(is.rsi.eligible, as.rsi)\n",
" - ", x_deparsed, " %>% mutate(across(where(is.rsi.eligible), as.rsi))", " - ", x_deparsed, " %>% mutate(across(where(is.rsi.eligible), as.rsi))")
call = FALSE)
} }
# Return data set --------------------------------------------------------- # Return data set ---------------------------------------------------------
@ -986,14 +984,14 @@ edit_rsi <- function(x,
TRUE TRUE
}) })
suppressWarnings(new_edits[rows, cols] <<- to) suppressWarnings(new_edits[rows, cols] <<- to)
warning_("Value \"", to, "\" added to the factor levels of column", ifelse(length(cols) == 1, "", "s"), warning_("in `eucast_rules()`: value \"", to, "\" added to the factor levels of column",
ifelse(length(cols) == 1, "", "s"),
" ", vector_and(cols, quotes = "`", sort = FALSE), " ", vector_and(cols, quotes = "`", sort = FALSE),
" because this value was not an existing factor level.", " because this value was not an existing factor level.")
call = FALSE)
txt_warning() txt_warning()
warned <- FALSE warned <- FALSE
} else { } else {
warning_(w$message, call = FALSE) warning_("in `eucast_rules()`: ", w$message)
txt_warning() txt_warning()
} }
}, },

View File

@ -267,7 +267,6 @@ get_column_abx <- function(x,
", as it is already set for ", ", as it is already set for ",
names(already_set_as), " (", ab_name(names(already_set_as), tolower = TRUE, language = NULL), ")"), names(already_set_as), " (", ab_name(names(already_set_as), tolower = TRUE, language = NULL), ")"),
add_fn = font_red, add_fn = font_red,
call = FALSE,
immediate = verbose) immediate = verbose)
} }
} }
@ -338,6 +337,5 @@ generate_warning_abs_missing <- function(missing, any = FALSE) {
} }
warning_(paste0("Introducing NAs since", any_txt[1], " these antimicrobials ", any_txt[2], " required: ", warning_(paste0("Introducing NAs since", any_txt[1], " these antimicrobials ", any_txt[2], " required: ",
vector_and(missing, quotes = FALSE)), vector_and(missing, quotes = FALSE)),
immediate = TRUE, immediate = TRUE)
call = FALSE)
} }

View File

@ -170,7 +170,7 @@ join_microorganisms <- function(type, x, by, suffix, ...) {
} }
if (type %like% "full|left|right|inner" && NROW(joined) > NROW(x)) { if (type %like% "full|left|right|inner" && NROW(joined) > NROW(x)) {
warning_("The newly joined data set contains ", nrow(joined) - nrow(x), " rows more than the number of rows of `x`.", call = FALSE) warning_("in `", type, "_join()`: the newly joined data set contains ", nrow(joined) - nrow(x), " rows more than the number of rows of `x`.")
} }
joined joined

View File

@ -150,7 +150,7 @@ key_antimicrobials <- function(x = NULL,
col_mo <- search_type_in_df(x = x, type = "mo", info = FALSE) col_mo <- search_type_in_df(x = x, type = "mo", info = FALSE)
} }
if (is.null(col_mo)) { if (is.null(col_mo)) {
warning_("No column found for `col_mo`, ignoring antibiotics set in `gram_negative` and `gram_positive`, and antimycotics set in `antifungal`", call = FALSE) warning_("in `key_antimicrobials()`: no column found for `col_mo`, ignoring antibiotics set in `gram_negative` and `gram_positive`, and antimycotics set in `antifungal`")
gramstain <- NA_character_ gramstain <- NA_character_
kingdom <- NA_character_ kingdom <- NA_character_
} else { } else {
@ -172,11 +172,11 @@ key_antimicrobials <- function(x = NULL,
if (values_new_length < values_old_length & if (values_new_length < values_old_length &
any(filter, na.rm = TRUE) & any(filter, na.rm = TRUE) &
message_not_thrown_before("key_antimicrobials", name)) { message_not_thrown_before("key_antimicrobials", name)) {
warning_(ifelse(values_new_length == 0, warning_("in `key_antimicrobials()`: ",
ifelse(values_new_length == 0,
"No columns available ", "No columns available ",
paste0("Only using ", values_new_length, " out of ", values_old_length, " defined columns ")), paste0("Only using ", values_new_length, " out of ", values_old_length, " defined columns ")),
"as key antimicrobials for ", name, "s. See ?key_antimicrobials.", "as key antimicrobials for ", name, "s. See ?key_antimicrobials.")
call = FALSE)
} }
generate_antimcrobials_string(x[which(filter), c(universal, values), drop = FALSE]) generate_antimcrobials_string(x[which(filter), c(universal, values), drop = FALSE])
@ -217,7 +217,7 @@ key_antimicrobials <- function(x = NULL,
cols = cols) cols = cols)
if (length(unique(key_ab)) == 1) { if (length(unique(key_ab)) == 1) {
warning_("No distinct key antibiotics determined.", call = FALSE) warning_("in `key_antimicrobials()`: no distinct key antibiotics determined.")
} }
key_ab key_ab

View File

@ -32,23 +32,23 @@
#' @rdname lifecycle #' @rdname lifecycle
#' @description Functions in this `AMR` package are categorised using [the lifecycle circle of the Tidyverse as found on www.tidyverse.org/lifecycle](https://lifecycle.r-lib.org/articles/stages.html). #' @description Functions in this `AMR` package are categorised using [the lifecycle circle of the Tidyverse as found on www.tidyverse.org/lifecycle](https://lifecycle.r-lib.org/articles/stages.html).
#' #'
#' \if{html}{\figure{lifecycle_tidyverse.svg}{options: height=200px style=margin-bottom:5px} \cr} #' \if{html}{\figure{lifecycle_tidyverse.svg}{options: height="200" style=margin-bottom:"5"} \cr}
#' This page contains a section for every lifecycle (with text borrowed from the aforementioned Tidyverse website), so they can be used in the manual pages of the functions. #' This page contains a section for every lifecycle (with text borrowed from the aforementioned Tidyverse website), so they can be used in the manual pages of the functions.
#' @section Experimental Lifecycle: #' @section Experimental Lifecycle:
#' \if{html}{\figure{lifecycle_experimental.svg}{options: style=margin-bottom:5px} \cr} #' \if{html}{\figure{lifecycle_experimental.svg}{options: style=margin-bottom:"5"} \cr}
#' The [lifecycle][AMR::lifecycle] of this function is **experimental**. An experimental function is in early stages of development. The unlying code might be changing frequently. Experimental functions might be removed without deprecation, so you are generally best off waiting until a function is more mature before you use it in production code. Experimental functions are only available in development versions of this `AMR` package and will thus not be included in releases that are submitted to CRAN, since such functions have not yet matured enough. #' The [lifecycle][AMR::lifecycle] of this function is **experimental**. An experimental function is in early stages of development. The unlying code might be changing frequently. Experimental functions might be removed without deprecation, so you are generally best off waiting until a function is more mature before you use it in production code. Experimental functions are only available in development versions of this `AMR` package and will thus not be included in releases that are submitted to CRAN, since such functions have not yet matured enough.
#' @section Maturing Lifecycle: #' @section Maturing Lifecycle:
#' \if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:5px} \cr} #' \if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:"5"} \cr}
#' The [lifecycle][AMR::lifecycle] of this function is **maturing**. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome [to suggest changes at our repository](https://github.com/msberends/AMR/issues) or [write us an email (see section 'Contact Us')][AMR::AMR]. #' The [lifecycle][AMR::lifecycle] of this function is **maturing**. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome [to suggest changes at our repository](https://github.com/msberends/AMR/issues) or [write us an email (see section 'Contact Us')][AMR::AMR].
#' @section Stable Lifecycle: #' @section Stable Lifecycle:
#' \if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} #' \if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:"5"} \cr}
#' The [lifecycle][AMR::lifecycle] of this function is **stable**. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided. #' The [lifecycle][AMR::lifecycle] of this function is **stable**. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.
#' #'
#' If the unlying code needs breaking changes, they will occur gradually. For example, an argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. #' If the unlying code needs breaking changes, they will occur gradually. For example, an argument will be deprecated and first continue to work, but will emit a message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
#' @section Retired Lifecycle: #' @section Retired Lifecycle:
#' \if{html}{\figure{lifecycle_retired.svg}{options: style=margin-bottom:5px} \cr} #' \if{html}{\figure{lifecycle_retired.svg}{options: style=margin-bottom:"5"} \cr}
#' The [lifecycle][AMR::lifecycle] of this function is **retired**. A retired function is no longer under active development, and (if appropiate) a better alternative is available. No new arguments will be added, and only the most critical bugs will be fixed. In a future version, this function will be removed. #' The [lifecycle][AMR::lifecycle] of this function is **retired**. A retired function is no longer under active development, and (if appropiate) a better alternative is available. No new arguments will be added, and only the most critical bugs will be fixed. In a future version, this function will be removed.
#' @section Questioning Lifecycle: #' @section Questioning Lifecycle:
#' \if{html}{\figure{lifecycle_questioning.svg}{options: style=margin-bottom:5px} \cr} #' \if{html}{\figure{lifecycle_questioning.svg}{options: style=margin-bottom:"5"} \cr}
#' The [lifecycle][AMR::lifecycle] of this function is **questioning**. This function might be no longer be optimal approach, or is it questionable whether this function should be in this `AMR` package at all. #' The [lifecycle][AMR::lifecycle] of this function is **questioning**. This function might be no longer be optimal approach, or is it questionable whether this function should be in this `AMR` package at all.
NULL NULL

View File

@ -65,7 +65,7 @@
#' #'
#' * `guideline = "TB"` #' * `guideline = "TB"`
#' #'
#' The international guideline for multi-drug resistant tuberculosis - World Health Organization "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" ([link](https://www.who.int/tb/publications/pmdt_companionhandbook/en/)) #' The international guideline for multi-drug resistant tuberculosis - World Health Organization "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" ([link](https://www.who.int/publications/i/item/9789241548809))
#' #'
#' * `guideline = "MRGN"` #' * `guideline = "MRGN"`
#' #'
@ -240,7 +240,7 @@ mdro <- function(x = NULL,
} }
if (!is.null(list(...)$country)) { if (!is.null(list(...)$country)) {
warning_("Using `country` is deprecated, use `guideline` instead. See ?mdro.", call = FALSE) warning_("in `mdro()`: using `country` is deprecated, use `guideline` instead. See ?mdro")
guideline <- list(...)$country guideline <- list(...)$country
} }
@ -343,7 +343,7 @@ mdro <- function(x = NULL,
guideline$name <- "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" guideline$name <- "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis"
guideline$author <- "WHO (World Health Organization)" guideline$author <- "WHO (World Health Organization)"
guideline$version <- "WHO/HTM/TB/2014.11, 2014" guideline$version <- "WHO/HTM/TB/2014.11, 2014"
guideline$source_url <- "https://www.who.int/tb/publications/pmdt_companionhandbook/en/" guideline$source_url <- "https://www.who.int/publications/i/item/9789241548809"
guideline$type <- "MDR-TB's" guideline$type <- "MDR-TB's"
# support per country: # support per country:
@ -1550,8 +1550,8 @@ mdro <- function(x = NULL,
if (guideline$code == "cmi2012") { if (guideline$code == "cmi2012") {
if (any(x$MDRO == -1, na.rm = TRUE)) { if (any(x$MDRO == -1, na.rm = TRUE)) {
if (message_not_thrown_before("mdro", "availability")) { if (message_not_thrown_before("mdro", "availability")) {
warning_("NA introduced for isolates where the available percentage of antimicrobial classes was below ", warning_("in `mdro()`: NA introduced for isolates where the available percentage of antimicrobial classes was below ",
percentage(pct_required_classes), " (set with `pct_required_classes`)", call = FALSE) percentage(pct_required_classes), " (set with `pct_required_classes`)")
} }
# set these -1s to NA # set these -1s to NA
x[which(x$MDRO == -1), "MDRO"] <- NA_integer_ x[which(x$MDRO == -1), "MDRO"] <- NA_integer_
@ -1709,7 +1709,7 @@ run_custom_mdro_guideline <- function(df, guideline, info) {
return("error") return("error")
}) })
if (identical(qry, "error")) { if (identical(qry, "error")) {
warning_("in custom_mdro_guideline(): rule ", i, warning_("in `custom_mdro_guideline()`: rule ", i,
" (`", as.character(guideline[[i]]$query), "`) was ignored because of this error message: ", " (`", as.character(guideline[[i]]$query), "`) was ignored because of this error message: ",
pkg_env$err_msg, pkg_env$err_msg,
call = FALSE, call = FALSE,

46
R/mic.R
View File

@ -37,8 +37,8 @@ valid_mic_levels <- c(c(t(vapply(FUN.VALUE = character(9), ops,
function(x) paste0(x, sort(c(1:9, 1.5)))))), function(x) paste0(x, sort(c(1:9, 1.5)))))),
c(t(vapply(FUN.VALUE = character(45), ops, c(t(vapply(FUN.VALUE = character(45), ops,
function(x) paste0(x, c(10:98)[9:98 %% 2 == TRUE])))), function(x) paste0(x, c(10:98)[9:98 %% 2 == TRUE])))),
c(t(vapply(FUN.VALUE = character(16), ops, c(t(vapply(FUN.VALUE = character(17), ops,
function(x) paste0(x, sort(c(2 ^ c(7:11), 80 * c(2:12)))))))) function(x) paste0(x, sort(c(2 ^ c(7:11), 192, 80 * c(2:12))))))))
#' Transform Input to Minimum Inhibitory Concentrations (MIC) #' Transform Input to Minimum Inhibitory Concentrations (MIC)
#' #'
@ -47,7 +47,8 @@ valid_mic_levels <- c(c(t(vapply(FUN.VALUE = character(9), ops,
#' @rdname as.mic #' @rdname as.mic
#' @param x a [character] or [numeric] vector #' @param x a [character] or [numeric] vector
#' @param na.rm a [logical] indicating whether missing values should be removed #' @param na.rm a [logical] indicating whether missing values should be removed
#' @details To interpret MIC values as RSI values, use [as.rsi()] on MIC values. It supports guidelines from EUCAST and CLSI. #' @param ... arguments passed on to methods
#' @details To interpret MIC values as RSI values, use [as.rsi()] on MIC values. It supports guidelines from EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`).
#' #'
#' This class for MIC values is a quite a special data type: formally it is an ordered [factor] with valid MIC values as [factor] levels (to make sure only valid MIC values are retained), but for any mathematical operation it acts as decimal numbers: #' This class for MIC values is a quite a special data type: formally it is an ordered [factor] with valid MIC values as [factor] levels (to make sure only valid MIC values are retained), but for any mathematical operation it acts as decimal numbers:
#' #'
@ -86,6 +87,10 @@ valid_mic_levels <- c(c(t(vapply(FUN.VALUE = character(9), ops,
#' ``` #' ```
#' #'
#' The following [generic functions][groupGeneric()] are implemented for the MIC class: `!`, `!=`, `%%`, `%/%`, `&`, `*`, `+`, `-`, `/`, `<`, `<=`, `==`, `>`, `>=`, `^`, `|`, [abs()], [acos()], [acosh()], [all()], [any()], [asin()], [asinh()], [atan()], [atanh()], [ceiling()], [cos()], [cosh()], [cospi()], [cummax()], [cummin()], [cumprod()], [cumsum()], [digamma()], [exp()], [expm1()], [floor()], [gamma()], [lgamma()], [log()], [log1p()], [log2()], [log10()], [max()], [mean()], [min()], [prod()], [range()], [round()], [sign()], [signif()], [sin()], [sinh()], [sinpi()], [sqrt()], [sum()], [tan()], [tanh()], [tanpi()], [trigamma()] and [trunc()]. Some functions of the `stats` package are also implemented: [median()], [quantile()], [mad()], [IQR()], [fivenum()]. Also, [boxplot.stats()] is supported. Since [sd()] and [var()] are non-generic functions, these could not be extended. Use [mad()] as an alternative, or use e.g. `sd(as.numeric(x))` where `x` is your vector of MIC values. #' The following [generic functions][groupGeneric()] are implemented for the MIC class: `!`, `!=`, `%%`, `%/%`, `&`, `*`, `+`, `-`, `/`, `<`, `<=`, `==`, `>`, `>=`, `^`, `|`, [abs()], [acos()], [acosh()], [all()], [any()], [asin()], [asinh()], [atan()], [atanh()], [ceiling()], [cos()], [cosh()], [cospi()], [cummax()], [cummin()], [cumprod()], [cumsum()], [digamma()], [exp()], [expm1()], [floor()], [gamma()], [lgamma()], [log()], [log1p()], [log2()], [log10()], [max()], [mean()], [min()], [prod()], [range()], [round()], [sign()], [signif()], [sin()], [sinh()], [sinpi()], [sqrt()], [sum()], [tan()], [tanh()], [tanpi()], [trigamma()] and [trunc()]. Some functions of the `stats` package are also implemented: [median()], [quantile()], [mad()], [IQR()], [fivenum()]. Also, [boxplot.stats()] is supported. Since [sd()] and [var()] are non-generic functions, these could not be extended. Use [mad()] as an alternative, or use e.g. `sd(as.numeric(x))` where `x` is your vector of MIC values.
#'
#' Using [as.double()] or [as.numeric()] on MIC values will remove the operators and return a numeric vector. Do **not** use [as.integer()] on MIC values as by the \R convention on [factor]s, it will return the index of the factor levels (which is often useless for regular users).
#'
#' Use [droplevels()] to drop unused levels. At default, it will return a plain factor. Use `droplevels(..., as.mic = TRUE)` to maintain the `<mic>` class.
#' @return Ordered [factor] with additional class [`mic`], that in mathematical operations acts as decimal numbers. Bare in mind that the outcome of any mathematical operation on MICs will return a [numeric] value. #' @return Ordered [factor] with additional class [`mic`], that in mathematical operations acts as decimal numbers. Bare in mind that the outcome of any mathematical operation on MICs will return a [numeric] value.
#' @aliases mic #' @aliases mic
#' @export #' @export
@ -175,7 +180,7 @@ as.mic <- function(x, na.rm = FALSE) {
unique() %pm>% unique() %pm>%
sort() %pm>% sort() %pm>%
vector_and(quotes = TRUE) vector_and(quotes = TRUE)
warning_(na_after - na_before, " results truncated (", warning_("in `as.mic()`: ", na_after - na_before, " results truncated (",
round(((na_after - na_before) / length(x)) * 100), round(((na_after - na_before) / length(x)) * 100),
"%) that were invalid MICs: ", "%) that were invalid MICs: ",
list_missing, call = FALSE) list_missing, call = FALSE)
@ -196,7 +201,8 @@ all_valid_mics <- function(x) {
} }
#' @rdname as.mic #' @rdname as.mic
#' @details `NA_mic_` is a missing value of the new `<mic>` class. #' @details `NA_mic_` is a missing value of the new `<mic>` class, analogous to e.g. base \R's [`NA_character_`][base::NA].
#' @format NULL
#' @export #' @export
NA_mic_ <- set_clean_class(factor(NA, levels = valid_mic_levels, ordered = TRUE), NA_mic_ <- set_clean_class(factor(NA, levels = valid_mic_levels, ordered = TRUE),
new_class = c("mic", "ordered", "factor")) new_class = c("mic", "ordered", "factor"))
@ -214,13 +220,6 @@ as.double.mic <- function(x, ...) {
as.double(gsub("[<=>]+", "", as.character(x), perl = TRUE)) as.double(gsub("[<=>]+", "", as.character(x), perl = TRUE))
} }
#' @method as.integer mic
#' @export
#' @noRd
as.integer.mic <- function(x, ...) {
as.integer(gsub("[<=>]+", "", as.character(x), perl = TRUE))
}
#' @method as.numeric mic #' @method as.numeric mic
#' @export #' @export
#' @noRd #' @noRd
@ -228,11 +227,12 @@ as.numeric.mic <- function(x, ...) {
as.numeric(gsub("[<=>]+", "", as.character(x), perl = TRUE)) as.numeric(gsub("[<=>]+", "", as.character(x), perl = TRUE))
} }
#' @rdname as.mic
#' @method droplevels mic #' @method droplevels mic
#' @param as.mic a [logical] to indicate whether the `<mic>` class should be kept, defaults to `FALSE`
#' @export #' @export
#' @noRd droplevels.mic <- function(x, as.mic = FALSE, ...) {
droplevels.mic <- function(x, exclude = if (any(is.na(levels(x)))) NULL else NA, as.mic = TRUE, ...) { x <- droplevels.factor(x, ...)
x <- droplevels.factor(x, exclude = exclude, ...)
if (as.mic == TRUE) { if (as.mic == TRUE) {
class(x) <- c("mic", "ordered", "factor") class(x) <- c("mic", "ordered", "factor")
} }
@ -243,12 +243,12 @@ droplevels.mic <- function(x, exclude = if (any(is.na(levels(x)))) NULL else NA,
pillar_shaft.mic <- function(x, ...) { pillar_shaft.mic <- function(x, ...) {
crude_numbers <- as.double(x) crude_numbers <- as.double(x)
operators <- gsub("[^<=>]+", "", as.character(x)) operators <- gsub("[^<=>]+", "", as.character(x))
pasted <- trimws(paste0(operators, trimws(format(crude_numbers)))) operators[!is.na(operators) & operators != ""] <- font_silver(operators[!is.na(operators) & operators != ""], collapse = NULL)
out <- pasted out <- trimws(paste0(operators, trimws(format(crude_numbers))))
out[is.na(x)] <- font_na(NA) out[is.na(x)] <- font_na(NA)
out <- gsub("(<|=|>)", font_silver("\\1"), out) # maketrailing zeroes almost invisible
out <- gsub("([.]?0+)$", font_white("\\1"), out) out[out %like% "[.]"] <- gsub("([.]?0+)$", font_white("\\1"), out[out %like% "[.]"], perl = TRUE)
create_pillar_column(out, align = "right", width = max(nchar(pasted))) create_pillar_column(out, align = "right", width = max(nchar(font_stripstyle(out))))
} }
# will be exported using s3_register() in R/zzz.R # will be exported using s3_register() in R/zzz.R
@ -260,7 +260,9 @@ type_sum.mic <- function(x, ...) {
#' @export #' @export
#' @noRd #' @noRd
print.mic <- function(x, ...) { print.mic <- function(x, ...) {
cat("Class <mic>\n") cat("Class <mic>",
ifelse(length(levels(x)) < length(valid_mic_levels), font_red(" with dropped levels"), ""),
"\n", sep = "")
print(as.character(x), quote = FALSE) print(as.character(x), quote = FALSE)
att <- attributes(x) att <- attributes(x)
if ("na.action" %in% names(att)) { if ("na.action" %in% names(att)) {
@ -358,7 +360,7 @@ sort.mic <- function(x, decreasing = FALSE, ...) {
#' @export #' @export
#' @noRd #' @noRd
hist.mic <- function(x, ...) { hist.mic <- function(x, ...) {
warning_("Use `plot()` or ggplot2's `autoplot()` for optimal plotting of MIC values", call = FALSE) warning_("in `hist()`: use `plot()` or ggplot2's `autoplot()` for optimal plotting of MIC values")
hist(log2(x)) hist(log2(x))
} }

139
R/mo.R
View File

@ -31,9 +31,9 @@
#' @param Becker a [logical] to indicate whether staphylococci should be categorised into coagulase-negative staphylococci ("CoNS") and coagulase-positive staphylococci ("CoPS") instead of their own species, according to Karsten Becker *et al.* (1,2,3). #' @param Becker a [logical] to indicate whether staphylococci should be categorised into coagulase-negative staphylococci ("CoNS") and coagulase-positive staphylococci ("CoPS") instead of their own species, according to Karsten Becker *et al.* (1,2,3).
#' #'
#' This excludes *Staphylococcus aureus* at default, use `Becker = "all"` to also categorise *S. aureus* as "CoPS". #' This excludes *Staphylococcus aureus* at default, use `Becker = "all"` to also categorise *S. aureus* as "CoPS".
#' @param Lancefield a [logical] to indicate whether beta-haemolytic *Streptococci* should be categorised into Lancefield groups instead of their own species, according to Rebecca C. Lancefield (4). These *Streptococci* will be categorised in their first group, e.g. *Streptococcus dysgalactiae* will be group C, although officially it was also categorised into groups G and L. #' @param Lancefield a [logical] to indicate whether a beta-haemolytic *Streptococcus* should be categorised into Lancefield groups instead of their own species, according to Rebecca C. Lancefield (4). These streptococci will be categorised in their first group, e.g. *Streptococcus dysgalactiae* will be group C, although officially it was also categorised into groups G and L.
#' #'
#' This excludes *Enterococci* at default (who are in group D), use `Lancefield = "all"` to also categorise all *Enterococci* as group D. #' This excludes enterococci at default (who are in group D), use `Lancefield = "all"` to also categorise all enterococci as group D.
#' @param allow_uncertain a number between `0` (or `"none"`) and `3` (or `"all"`), or `TRUE` (= `2`) or `FALSE` (= `0`) to indicate whether the input should be checked for less probable results, see *Details* #' @param allow_uncertain a number between `0` (or `"none"`) and `3` (or `"all"`), or `TRUE` (= `2`) or `FALSE` (= `0`) to indicate whether the input should be checked for less probable results, see *Details*
#' @param reference_df a [data.frame] to be used for extra reference when translating `x` to a valid [`mo`]. See [set_mo_source()] and [get_mo_source()] to automate the usage of your own codes (e.g. used in your analysis or organisation). #' @param reference_df a [data.frame] to be used for extra reference when translating `x` to a valid [`mo`]. See [set_mo_source()] and [get_mo_source()] to automate the usage of your own codes (e.g. used in your analysis or organisation).
#' @param ignore_pattern a regular expression (case-insensitive) of which all matches in `x` must return `NA`. This can be convenient to exclude known non-relevant input and can also be set with the option `AMR_ignore_pattern`, e.g. `options(AMR_ignore_pattern = "(not reported|contaminated flora)")`. #' @param ignore_pattern a regular expression (case-insensitive) of which all matches in `x` must return `NA`. This can be convenient to exclude known non-relevant input and can also be set with the option `AMR_ignore_pattern`, e.g. `options(AMR_ignore_pattern = "(not reported|contaminated flora)")`.
@ -1003,6 +1003,35 @@ exec_as.mo <- function(x,
} }
} }
# try splitting of characters in the middle and then find ID based on old names ----
# only when text length is 6 or lower
# like esco = E. coli, klpn = K. pneumoniae, stau = S. aureus, staaur = S. aureus
if (nchar(g.x_backup_without_spp) <= 6) {
x_length <- nchar(g.x_backup_without_spp)
x_split <- paste0("^",
g.x_backup_without_spp %pm>% substr(1, x_length / 2),
".* ",
g.x_backup_without_spp %pm>% substr((x_length / 2) + 1, x_length))
found <- lookup(fullname_lower %like_case% x_split,
haystack = MO.old_lookup,
column = NULL)
if (!all(is.na(found))) {
# it's an old name, so return it
if (property == "ref") {
x[i] <- found["ref"]
} else {
x[i] <- lookup(fullname == found["fullname_new"], haystack = MO_lookup)
}
pkg_env$mo_renamed_last_run <- found["fullname"]
was_renamed(name_old = found["fullname"],
name_new = lookup(fullname == found["fullname_new"], "fullname", haystack = MO_lookup),
ref_old = found["ref"],
ref_new = lookup(fullname == found["fullname_new"], "ref", haystack = MO_lookup),
mo = lookup(fullname == found["fullname_new"], "mo", haystack = MO_lookup))
return(x[i])
}
}
# try fullname without start and without nchar limit of >= 6 ---- # try fullname without start and without nchar limit of >= 6 ----
# like "K. pneu rhino" >> "Klebsiella pneumoniae (rhinoscleromatis)" = KLEPNERH # like "K. pneu rhino" >> "Klebsiella pneumoniae (rhinoscleromatis)" = KLEPNERH
found <- lookup(fullname_lower %like_case% e.x_withspaces_start_only, found <- lookup(fullname_lower %like_case% e.x_withspaces_start_only,
@ -1188,9 +1217,38 @@ exec_as.mo <- function(x,
return(found) return(found)
} }
# (6) try to strip off half an element from end and check the remains ---- # (6) remove non-taxonomic prefix and suffix ----
if (isTRUE(debug)) { if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (6) try to strip off half an element from end and check the remains\n")) cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (6) remove non-taxonomic prefix and suffix\n"))
}
x_without_nontax <- gsub("(^[a-zA-Z]+[./-]+[a-zA-Z]+[^a-zA-Z]* )([a-zA-Z.]+ [a-zA-Z]+.*)",
"\\2", a.x_backup, perl = TRUE)
x_without_nontax <- gsub("( *[(].*[)] *)[^a-zA-Z]*$", "", x_without_nontax, perl = TRUE)
if (isTRUE(debug)) {
message("Running '", x_without_nontax, "'")
}
# first try without dyslexia mode
found <- suppressMessages(suppressWarnings(exec_as.mo(x_without_nontax, initial_search = FALSE, dyslexia_mode = FALSE, allow_uncertain = FALSE, debug = debug, reference_data_to_use = uncertain.reference_data_to_use, actual_uncertainty = 2, actual_input = x_without_nontax)))
if (empty_result(found)) {
# then with dyslexia mode
found <- suppressMessages(suppressWarnings(exec_as.mo(x_without_nontax, initial_search = FALSE, dyslexia_mode = TRUE, allow_uncertain = FALSE, debug = debug, reference_data_to_use = uncertain.reference_data_to_use, actual_uncertainty = 2, actual_input = x_without_nontax)))
}
if (!empty_result(found) & nchar(g.x_backup_without_spp) >= 6) {
# we ran with actual_input = x_without_nontax, so now correct for a.x_backup:
uncertain_df <- attr(found, which = "uncertainties", exact = TRUE)
uncertain_df$input <- a.x_backup
found_result <- found
uncertainties <<- rbind(uncertainties,
uncertain_df,
stringsAsFactors = FALSE)
found <- lookup(mo == found)
return(found)
}
# (7) try to strip off half an element from end and check the remains ----
if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (7) try to strip off half an element from end and check the remains\n"))
} }
x_strip <- a.x_backup %pm>% strsplit("[ .]") %pm>% unlist() x_strip <- a.x_backup %pm>% strsplit("[ .]") %pm>% unlist()
if (length(x_strip) > 1) { if (length(x_strip) > 1) {
@ -1220,9 +1278,9 @@ exec_as.mo <- function(x,
} }
} }
} }
# (7) try to strip off one element from end and check the remains ---- # (8) try to strip off one element from end and check the remains ----
if (isTRUE(debug)) { if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (7) try to strip off one element from end and check the remains\n")) cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (8) try to strip off one element from end and check the remains\n"))
} }
if (length(x_strip) > 1) { if (length(x_strip) > 1) {
for (i in seq_len(length(x_strip) - 1)) { for (i in seq_len(length(x_strip) - 1)) {
@ -1249,9 +1307,9 @@ exec_as.mo <- function(x,
} }
} }
} }
# (8) check for unknown yeasts/fungi ---- # (9) check for unknown yeasts/fungi ----
if (isTRUE(debug)) { if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (8) check for unknown yeasts/fungi\n")) cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (9) check for unknown yeasts/fungi\n"))
} }
if (b.x_trimmed %like_case% "yeast") { if (b.x_trimmed %like_case% "yeast") {
found <- "F_YEAST" found <- "F_YEAST"
@ -1275,9 +1333,9 @@ exec_as.mo <- function(x,
stringsAsFactors = FALSE) stringsAsFactors = FALSE)
return(found) return(found)
} }
# (9) try to strip off one element from start and check the remains (only allow >= 2-part name outcome) ---- # (10) try to strip off one element from start and check the remains (only allow >= 2-part name outcome) ----
if (isTRUE(debug)) { if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (9) try to strip off one element from start and check the remains (only allow >= 2-part name outcome)\n")) cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (10) try to strip off one element from start and check the remains (only allow >= 2-part name outcome)\n"))
} }
x_strip <- a.x_backup %pm>% strsplit("[ .]") %pm>% unlist() x_strip <- a.x_backup %pm>% strsplit("[ .]") %pm>% unlist()
if (length(x_strip) > 1 & nchar(g.x_backup_without_spp) >= 6) { if (length(x_strip) > 1 & nchar(g.x_backup_without_spp) >= 6) {
@ -1311,9 +1369,9 @@ exec_as.mo <- function(x,
if (uncertainty_level >= 3) { if (uncertainty_level >= 3) {
now_checks_for_uncertainty_level <- 3 now_checks_for_uncertainty_level <- 3
# (10) try to strip off one element from start and check the remains (any text size) ---- # (11) try to strip off one element from start and check the remains (any text size) ----
if (isTRUE(debug)) { if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (10) try to strip off one element from start and check the remains (any text size)\n")) cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (11) try to strip off one element from start and check the remains (any text size)\n"))
} }
x_strip <- a.x_backup %pm>% strsplit("[ .]") %pm>% unlist() x_strip <- a.x_backup %pm>% strsplit("[ .]") %pm>% unlist()
if (length(x_strip) > 1 & nchar(g.x_backup_without_spp) >= 6) { if (length(x_strip) > 1 & nchar(g.x_backup_without_spp) >= 6) {
@ -1338,10 +1396,10 @@ exec_as.mo <- function(x,
} }
} }
} }
# (11) try to strip off one element from end and check the remains (any text size) ---- # (12) try to strip off one element from end and check the remains (any text size) ----
# (this is in fact 7 but without nchar limit of >=6) # (this is in fact 7 but without nchar limit of >=6)
if (isTRUE(debug)) { if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (11) try to strip off one element from end and check the remains (any text size)\n")) cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (12) try to strip off one element from end and check the remains (any text size)\n"))
} }
if (length(x_strip) > 1) { if (length(x_strip) > 1) {
for (i in seq_len(length(x_strip) - 1)) { for (i in seq_len(length(x_strip) - 1)) {
@ -1366,9 +1424,9 @@ exec_as.mo <- function(x,
} }
} }
# (12) part of a name (very unlikely match) ---- # (13) part of a name (very unlikely match) ----
if (isTRUE(debug)) { if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (12) part of a name (very unlikely match)\n")) cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (13) part of a name (very unlikely match)\n"))
} }
if (isTRUE(debug)) { if (isTRUE(debug)) {
message("Running '", f.x_withspaces_end_only, "'") message("Running '", f.x_withspaces_end_only, "'")
@ -1460,9 +1518,8 @@ exec_as.mo <- function(x,
"You can also use your own reference data with set_mo_source() or directly, e.g.:\n", "You can also use your own reference data with set_mo_source() or directly, e.g.:\n",
' as.mo("mycode", reference_df = data.frame(own = "mycode", mo = "', MO_lookup$mo[match("Escherichia coli", MO_lookup$fullname)], '"))\n', ' as.mo("mycode", reference_df = data.frame(own = "mycode", mo = "', MO_lookup$mo[match("Escherichia coli", MO_lookup$fullname)], '"))\n',
' mo_name("mycode", reference_df = data.frame(own = "mycode", mo = "', MO_lookup$mo[match("Escherichia coli", MO_lookup$fullname)], '"))\n') ' mo_name("mycode", reference_df = data.frame(own = "mycode", mo = "', MO_lookup$mo[match("Escherichia coli", MO_lookup$fullname)], '"))\n')
warning_(paste0("\n", msg), warning_(paste0("\nin `as.mo()`: ", msg),
add_fn = font_red, add_fn = font_red,
call = FALSE,
immediate = TRUE) # thus will always be shown, even if >= warnings immediate = TRUE) # thus will always be shown, even if >= warnings
} }
# handling uncertainties ---- # handling uncertainties ----
@ -1502,12 +1559,11 @@ exec_as.mo <- function(x,
# comment below code if all staphylococcal species are categorised as CoNS/CoPS # comment below code if all staphylococcal species are categorised as CoNS/CoPS
if (any(x %in% MO_lookup[which(MO_lookup$species %in% post_Becker), property])) { if (any(x %in% MO_lookup[which(MO_lookup$species %in% post_Becker), property])) {
if (message_not_thrown_before("as.mo", "becker")) { if (message_not_thrown_before("as.mo", "becker")) {
warning_("Becker ", font_italic("et al."), " (2014, 2019, 2020) does not contain these species named after their publication: ", warning_("in `as.mo()`: Becker ", font_italic("et al."), " (2014, 2019, 2020) does not contain these species named after their publication: ",
font_italic(paste("S.", font_italic(paste("S.",
sort(mo_species(unique(x[x %in% MO_lookup[which(MO_lookup$species %in% post_Becker), property]]))), sort(mo_species(unique(x[x %in% MO_lookup[which(MO_lookup$species %in% post_Becker), property]]))),
collapse = ", ")), collapse = ", ")),
". Categorisation to CoNS/CoPS was taken from the original scientific publication(s).", ". Categorisation to CoNS/CoPS was taken from the original scientific publication(s).",
call = FALSE,
immediate = TRUE) immediate = TRUE)
} }
} }
@ -1680,8 +1736,7 @@ pillar_shaft.mo <- function(x, ...) {
col <- "The data" col <- "The data"
} }
warning_(col, " contains old MO codes (from a previous AMR package version). ", warning_(col, " contains old MO codes (from a previous AMR package version). ",
"Please update your MO codes with `as.mo()`.", "Please update your MO codes with `as.mo()`.")
call = FALSE)
} }
# make it always fit exactly # make it always fit exactly
@ -1755,8 +1810,7 @@ print.mo <- function(x, print.shortnames = FALSE, ...) {
names(x) <- x_names names(x) <- x_names
if (!all(x[!is.na(x)] %in% MO_lookup$mo)) { if (!all(x[!is.na(x)] %in% MO_lookup$mo)) {
warning_("Some MO codes are from a previous AMR package version. ", warning_("Some MO codes are from a previous AMR package version. ",
"Please update these MO codes with `as.mo()`.", "Please update the MO codes with `as.mo()`.")
call = FALSE)
} }
print.default(x, quote = FALSE) print.default(x, quote = FALSE)
} }
@ -1785,8 +1839,7 @@ summary.mo <- function(object, ...) {
as.data.frame.mo <- function(x, ...) { as.data.frame.mo <- function(x, ...) {
if (!all(x[!is.na(x)] %in% MO_lookup$mo)) { if (!all(x[!is.na(x)] %in% MO_lookup$mo)) {
warning_("The data contains old MO codes (from a previous AMR package version). ", warning_("The data contains old MO codes (from a previous AMR package version). ",
"Please update your MO codes with `as.mo()`.", "Please update your MO codes with `as.mo()`.")
call = FALSE)
} }
nm <- deparse1(substitute(x)) nm <- deparse1(substitute(x))
if (!"nm" %in% names(list(...))) { if (!"nm" %in% names(list(...))) {
@ -1882,7 +1935,7 @@ print.mo_uncertainties <- function(x, ...) {
if (NROW(x) == 0) { if (NROW(x) == 0) {
return(NULL) return(NULL)
} }
cat(word_wrap("Matching scores", ifelse(has_colour(), " (in blue)", ""), " are based on human pathogenic prevalence and the resemblance between the input and the full taxonomic name. See `?mo_matching_score`.\n\n", add_fn = font_blue)) cat(word_wrap("Matching scores", ifelse(has_colour(), " (in blue)", ""), " are based on pathogenicity in humans and the resemblance between the input and the full taxonomic name. See `?mo_matching_score`.\n\n", add_fn = font_blue))
txt <- "" txt <- ""
for (i in seq_len(nrow(x))) { for (i in seq_len(nrow(x))) {
@ -2090,24 +2143,22 @@ replace_old_mo_codes <- function(x, property) {
n_unique <- "" n_unique <- ""
} }
if (property != "mo") { if (property != "mo") {
warning_(paste0("The input contained ", n_matched, warning_("in `mo_", property, "()`: the input contained ", n_matched,
" old MO code", ifelse(n_matched == 1, "", "s"), " old MO code", ifelse(n_matched == 1, "", "s"),
" (", n_unique, "from a previous AMR package version). ", " (", n_unique, "from a previous AMR package version). ",
"Please update your MO codes with `as.mo()` to increase speed."), "Please update your MO codes with `as.mo()` to increase speed.")
call = FALSE)
} else { } else {
warning_(paste0("The input contained ", n_matched, warning_("in `as.mo()`: the input contained ", n_matched,
" old MO code", ifelse(n_matched == 1, "", "s"), " old MO code", ifelse(n_matched == 1, "", "s"),
" (", n_unique, "from a previous AMR package version). ", " (", n_unique, "from a previous AMR package version). ",
n_solved, " old MO code", ifelse(n_solved == 1, "", "s"), n_solved, " old MO code", ifelse(n_solved == 1, "", "s"),
ifelse(n_solved == 1, " was", " were"), ifelse(n_solved == 1, " was", " were"),
ifelse(all_direct_matches, " updated ", font_bold(" guessed ")), ifelse(all_direct_matches, " updated ", font_bold(" guessed ")),
"to ", ifelse(n_solved == 1, "a ", ""), "to ", ifelse(n_solved == 1, "a ", ""),
"currently used MO code", ifelse(n_solved == 1, "", "s"), "currently used MO code", ifelse(n_solved == 1, "", "s"),
ifelse(n_unsolved > 0, ifelse(n_unsolved > 0,
paste0(" and ", n_unsolved, " old MO code", ifelse(n_unsolved == 1, "", "s"), " could not be updated."), paste0(" and ", n_unsolved, " old MO code", ifelse(n_unsolved == 1, "", "s"), " could not be updated."),
".")), "."))
call = FALSE)
} }
} }
x x

View File

@ -27,13 +27,13 @@
#' #'
#' This algorithm is used by [as.mo()] and all the [`mo_*`][mo_property()] functions to determine the most probable match of taxonomic records based on user input. #' This algorithm is used by [as.mo()] and all the [`mo_*`][mo_property()] functions to determine the most probable match of taxonomic records based on user input.
#' @inheritSection lifecycle Stable Lifecycle #' @inheritSection lifecycle Stable Lifecycle
#' @author Dr. Matthijs Berends #' @author Dr Matthijs Berends
#' @param x Any user input value(s) #' @param x Any user input value(s)
#' @param n A full taxonomic name, that exists in [`microorganisms$fullname`][microorganisms] #' @param n A full taxonomic name, that exists in [`microorganisms$fullname`][microorganisms]
#' @section Matching Score for Microorganisms: #' @section Matching Score for Microorganisms:
#' With ambiguous user input in [as.mo()] and all the [`mo_*`][mo_property()] functions, the returned results are chosen based on their matching score using [mo_matching_score()]. This matching score \eqn{m}, is calculated as: #' With ambiguous user input in [as.mo()] and all the [`mo_*`][mo_property()] functions, the returned results are chosen based on their matching score using [mo_matching_score()]. This matching score \eqn{m}, is calculated as:
#' #'
#' \ifelse{latex}{\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}}}{\ifelse{html}{\figure{mo_matching_score.png}{options: width="300px" alt="mo matching score"}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p_n * k_n )}} #' \ifelse{latex}{\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}}}{\ifelse{html}{\figure{mo_matching_score.png}{options: width="300" alt="mo matching score"}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p_n * k_n )}}
#' #'
#' where: #' where:
#' #'
@ -49,6 +49,8 @@
#' All characters in \eqn{x} and \eqn{n} are ignored that are other than A-Z, a-z, 0-9, spaces and parentheses. #' All characters in \eqn{x} and \eqn{n} are ignored that are other than A-Z, a-z, 0-9, spaces and parentheses.
#' #'
#' All matches are sorted descending on their matching score and for all user input values, the top match will be returned. This will lead to the effect that e.g., `"E. coli"` will return the microbial ID of *Escherichia coli* (\eqn{m = `r round(mo_matching_score("E. coli", "Escherichia coli"), 3)`}, a highly prevalent microorganism found in humans) and not *Entamoeba coli* (\eqn{m = `r round(mo_matching_score("E. coli", "Entamoeba coli"), 3)`}, a less prevalent microorganism in humans), although the latter would alphabetically come first. #' All matches are sorted descending on their matching score and for all user input values, the top match will be returned. This will lead to the effect that e.g., `"E. coli"` will return the microbial ID of *Escherichia coli* (\eqn{m = `r round(mo_matching_score("E. coli", "Escherichia coli"), 3)`}, a highly prevalent microorganism found in humans) and not *Entamoeba coli* (\eqn{m = `r round(mo_matching_score("E. coli", "Entamoeba coli"), 3)`}, a less prevalent microorganism in humans), although the latter would alphabetically come first.
#'
#' Since `AMR` version 1.8.1, common microorganism abbreviations are ignored in determining the matching score. These abbreviations are currently: `r vector_and(pkg_env$mo_field_abbreviations, quotes = FALSE)`.
#' @export #' @export
#' @inheritSection AMR Reference Data Publicly Available #' @inheritSection AMR Reference Data Publicly Available
#' @inheritSection AMR Read more on Our Website! #' @inheritSection AMR Read more on Our Website!
@ -65,9 +67,16 @@ mo_matching_score <- function(x, n) {
x <- parse_and_convert(x) x <- parse_and_convert(x)
# no dots and other non-whitespace characters # no dots and other non-whitespace characters
x <- gsub("[^a-zA-Z0-9 \\(\\)]+", "", x) x <- gsub("[^a-zA-Z0-9 \\(\\)]+", "", x)
# remove abbreviations known to the field
x <- gsub(paste0("(^|[^a-z0-9]+)(",
paste0(pkg_env$mo_field_abbreviations, collapse = "|"),
")([^a-z0-9]+|$)"),
"", x, perl = TRUE, ignore.case = TRUE)
# only keep one space # only keep one space
x <- gsub(" +", " ", x) x <- gsub(" +", " ", x)
# n is always a taxonomically valid full name # n is always a taxonomically valid full name
if (length(n) == 1) { if (length(n) == 1) {
n <- rep(n, length(x)) n <- rep(n, length(x))
@ -82,7 +91,7 @@ mo_matching_score <- function(x, n) {
l_n.lev <- double(length = length(x)) l_n.lev <- double(length = length(x))
for (i in seq_len(length(x))) { for (i in seq_len(length(x))) {
# determine Levenshtein distance, but maximise to nchar of n # determine Levenshtein distance, but maximise to nchar of n
lev[i] <- utils::adist(x[i], n[i], ignore.case = FALSE, fixed = TRUE) lev[i] <- utils::adist(x[i], n[i], ignore.case = FALSE, fixed = TRUE, costs = c(ins = 1, del = 1, sub = 1))
# minimum of (l_n, Levenshtein distance) # minimum of (l_n, Levenshtein distance)
l_n.lev[i] <- min(l_n[i], as.double(lev[i])) l_n.lev[i] <- min(l_n[i], as.double(lev[i]))
} }

View File

@ -684,7 +684,7 @@ mo_url <- function(x, open = FALSE, language = get_AMR_locale(), ...) {
if (isTRUE(open)) { if (isTRUE(open)) {
if (length(u) > 1) { if (length(u) > 1) {
warning_("Only the first URL will be opened, as `browseURL()` only suports one string.") warning_("in `mo_url()`: only the first URL will be opened, as `browseURL()` only suports one string.")
} }
utils::browseURL(u[1L]) utils::browseURL(u[1L])
} }

View File

@ -29,16 +29,16 @@
#' #'
#' This is **the fastest way** to have your organisation (or analysis) specific codes picked up and translated by this package, since you don't have to bother about it again after setting it up once. #' This is **the fastest way** to have your organisation (or analysis) specific codes picked up and translated by this package, since you don't have to bother about it again after setting it up once.
#' @inheritSection lifecycle Stable Lifecycle #' @inheritSection lifecycle Stable Lifecycle
#' @param path location of your reference file, see *Details*. Can be `""`, `NULL` or `FALSE` to delete the reference file. #' @param path location of your reference file, this can be any text file (comma-, tab- or pipe-separated) or an Excel file (see *Details*). Can also be `""`, `NULL` or `FALSE` to delete the reference file.
#' @param destination destination of the compressed data file, default to the user's home directory. #' @param destination destination of the compressed data file, default to the user's home directory.
#' @rdname mo_source #' @rdname mo_source
#' @name mo_source #' @name mo_source
#' @aliases set_mo_source get_mo_source #' @aliases set_mo_source get_mo_source
#' @details The reference file can be a text file separated with commas (CSV) or tabs or pipes, an Excel file (either 'xls' or 'xlsx' format) or an \R object file (extension '.rds'). To use an Excel file, you will need to have the `readxl` package installed. #' @details The reference file can be a text file separated with commas (CSV) or tabs or pipes, an Excel file (either 'xls' or 'xlsx' format) or an \R object file (extension '.rds'). To use an Excel file, you will need to have the `readxl` package installed.
#' #'
#' [set_mo_source()] will check the file for validity: it must be a [data.frame], must have a column named `"mo"` which contains values from [`microorganisms$mo`][microorganisms] and must have a reference column with your own defined values. If all tests pass, [set_mo_source()] will read the file into \R and will ask to export it to `"~/mo_source.rds"`. The CRAN policy disallows packages to write to the file system, although '*exceptions may be allowed in interactive sessions if the package obtains confirmation from the user*'. For this reason, this function only works in interactive sessions so that the user can **specifically confirm and allow** that this file will be created. The destination of this file can be set with the `destination` argument and defaults to the user's home directory. It can also be set as an \R option, using `options(AMR_mo_source = "my/location/file.rds")`. #' [set_mo_source()] will check the file for validity: it must be a [data.frame], must have a column named `"mo"` which contains values from [`microorganisms$mo`][microorganisms] or [`microorganisms$fullname`][microorganisms] and must have a reference column with your own defined values. If all tests pass, [set_mo_source()] will read the file into \R and will ask to export it to `"~/mo_source.rds"`. The CRAN policy disallows packages to write to the file system, although '*exceptions may be allowed in interactive sessions if the package obtains confirmation from the user*'. For this reason, this function only works in interactive sessions so that the user can **specifically confirm and allow** that this file will be created. The destination of this file can be set with the `destination` argument and defaults to the user's home directory. It can also be set as an \R option, using `options(AMR_mo_source = "my/location/file.rds")`.
#' #'
#' The created compressed data file `"mo_source.rds"` will be used at default for MO determination (function [as.mo()] and consequently all `mo_*` functions like [mo_genus()] and [mo_gramstain()]). The location and timestamp of the original file will be saved as an attribute to the compressed data file. #' The created compressed data file `"mo_source.rds"` will be used at default for MO determination (function [as.mo()] and consequently all `mo_*` functions like [mo_genus()] and [mo_gramstain()]). The location and timestamp of the original file will be saved as an [attribute][base::attributes()] to the compressed data file.
#' #'
#' The function [get_mo_source()] will return the data set by reading `"mo_source.rds"` with [readRDS()]. If the original file has changed (by checking the location and timestamp of the original file), it will call [set_mo_source()] to update the data file automatically if used in an interactive session. #' The function [get_mo_source()] will return the data set by reading `"mo_source.rds"` with [readRDS()]. If the original file has changed (by checking the location and timestamp of the original file), it will call [set_mo_source()] to update the data file automatically if used in an interactive session.
#' #'
@ -46,15 +46,15 @@
#' #'
#' @section How to Setup: #' @section How to Setup:
#' #'
#' Imagine this data on a sheet of an Excel file (mo codes were looked up in the [microorganisms] data set). The first column contains the organisation specific codes, the second column contains an MO code from this package: #' Imagine this data on a sheet of an Excel file. The first column contains the organisation specific codes, the second column contains valid taxonomic names:
#' #'
#' ``` #' ```
#' | A | B | #' | A | B |
#' --|--------------------|--------------| #' --|--------------------|-----------------------|
#' 1 | Organisation XYZ | mo | #' 1 | Organisation XYZ | mo |
#' 2 | lab_mo_ecoli | B_ESCHR_COLI | #' 2 | lab_mo_ecoli | Escherichia coli |
#' 3 | lab_mo_kpneumoniae | B_KLBSL_PNMN | #' 3 | lab_mo_kpneumoniae | Klebsiella pneumoniae |
#' 4 | | | #' 4 | | |
#' ``` #' ```
#' #'
#' We save it as `"home/me/ourcodes.xlsx"`. Now we have to set it as a source: #' We save it as `"home/me/ourcodes.xlsx"`. Now we have to set it as a source:
@ -89,13 +89,13 @@
#' If we edit the Excel file by, let's say, adding row 4 like this: #' If we edit the Excel file by, let's say, adding row 4 like this:
#' #'
#' ``` #' ```
#' | A | B | #' | A | B |
#' --|--------------------|--------------| #' --|--------------------|-----------------------|
#' 1 | Organisation XYZ | mo | #' 1 | Organisation XYZ | mo |
#' 2 | lab_mo_ecoli | B_ESCHR_COLI | #' 2 | lab_mo_ecoli | Escherichia coli |
#' 3 | lab_mo_kpneumoniae | B_KLBSL_PNMN | #' 3 | lab_mo_kpneumoniae | Klebsiella pneumoniae |
#' 4 | lab_Staph_aureus | B_STPHY_AURS | #' 4 | lab_Staph_aureus | Staphylococcus aureus |
#' 5 | | | #' 5 | | |
#' ``` #' ```
#' #'
#' ...any new usage of an MO function in this package will update your data file: #' ...any new usage of an MO function in this package will update your data file:
@ -144,6 +144,7 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s
stop_ifnot(file.exists(path), "file not found: ", path) stop_ifnot(file.exists(path), "file not found: ", path)
df <- NULL
if (path %like% "[.]rds$") { if (path %like% "[.]rds$") {
df <- readRDS(path) df <- readRDS(path)
@ -153,28 +154,34 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s
df <- readxl::read_excel(path) df <- readxl::read_excel(path)
} else if (path %like% "[.]tsv$") { } else if (path %like% "[.]tsv$") {
df <- utils::read.table(header = TRUE, sep = "\t", stringsAsFactors = FALSE) df <- utils::read.table(file = path, header = TRUE, sep = "\t", stringsAsFactors = FALSE)
} else if (path %like% "[.]csv$") {
df <- utils::read.table(file = path, header = TRUE, sep = ",", stringsAsFactors = FALSE)
} else { } else {
# try comma first # try comma first
try( try(
df <- utils::read.table(header = TRUE, sep = ",", stringsAsFactors = FALSE), df <- utils::read.table(file = path, header = TRUE, sep = ",", stringsAsFactors = FALSE),
silent = TRUE) silent = TRUE)
if (!check_validity_mo_source(df, stop_on_error = FALSE)) { if (!check_validity_mo_source(df, stop_on_error = FALSE)) {
# try tab # try tab
try( try(
df <- utils::read.table(header = TRUE, sep = "\t", stringsAsFactors = FALSE), df <- utils::read.table(file = path, header = TRUE, sep = "\t", stringsAsFactors = FALSE),
silent = TRUE) silent = TRUE)
} }
if (!check_validity_mo_source(df, stop_on_error = FALSE)) { if (!check_validity_mo_source(df, stop_on_error = FALSE)) {
# try pipe # try pipe
try( try(
df <- utils::read.table(header = TRUE, sep = "|", stringsAsFactors = FALSE), df <- utils::read.table(file = path, header = TRUE, sep = "|", stringsAsFactors = FALSE),
silent = TRUE) silent = TRUE)
} }
} }
# check integrity # check integrity
if (is.null(df)) {
stop_("the path '", path, "' could not be imported as a dataset.")
}
check_validity_mo_source(df) check_validity_mo_source(df)
df <- subset(df, !is.na(mo)) df <- subset(df, !is.na(mo))
@ -187,7 +194,7 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s
} }
df <- as.data.frame(df, stringAsFactors = FALSE) df <- as.data.frame(df, stringAsFactors = FALSE)
df[, "mo"] <- set_clean_class(df[, "mo", drop = TRUE], c("mo", "character")) df[, "mo"] <- as.mo(df[, "mo", drop = TRUE])
# success # success
if (file.exists(mo_source_destination)) { if (file.exists(mo_source_destination)) {
@ -275,9 +282,9 @@ check_validity_mo_source <- function(x, refer_to_name = "`reference_df`", stop_o
return(FALSE) return(FALSE)
} }
} }
if (!all(x$mo %in% c("", microorganisms$mo), na.rm = TRUE)) { if (!all(x$mo %in% c("", microorganisms$mo, microorganisms$fullname), na.rm = TRUE)) {
if (stop_on_error == TRUE) { if (stop_on_error == TRUE) {
invalid <- x[which(!x$mo %in% c("", microorganisms$mo)), , drop = FALSE] invalid <- x[which(!x$mo %in% c("", microorganisms$mo, microorganisms$fullname)), , drop = FALSE]
if (nrow(invalid) > 1) { if (nrow(invalid) > 1) {
plural <- "s" plural <- "s"
} else { } else {

View File

@ -98,7 +98,7 @@ pca <- function(x,
x <- as.data.frame(new_list, stringsAsFactors = FALSE) x <- as.data.frame(new_list, stringsAsFactors = FALSE)
if (any(vapply(FUN.VALUE = logical(1), x, function(y) !is.numeric(y)))) { if (any(vapply(FUN.VALUE = logical(1), x, function(y) !is.numeric(y)))) {
warning_("Be sure to first calculate the resistance (or susceptibility) of variables with antimicrobial test results, since PCA works with [numeric] variables only. See Examples in ?pca.", call = FALSE) warning_("in `pca()`: be sure to first calculate the resistance (or susceptibility) of variables with antimicrobial test results, since PCA works with numeric variables only. See Examples in ?pca.", call = FALSE)
} }
# set column names # set column names

View File

@ -79,7 +79,7 @@ plot.mic <- function(x,
mo = NULL, mo = NULL,
ab = NULL, ab = NULL,
guideline = "EUCAST", guideline = "EUCAST",
main = paste("MIC values of", deparse(substitute(x))), main = deparse(substitute(x)),
ylab = "Frequency", ylab = "Frequency",
xlab = "Minimum Inhibitory Concentration (mg/L)", xlab = "Minimum Inhibitory Concentration (mg/L)",
colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"),
@ -166,7 +166,7 @@ barplot.mic <- function(height,
mo = NULL, mo = NULL,
ab = NULL, ab = NULL,
guideline = "EUCAST", guideline = "EUCAST",
main = paste("MIC values of", deparse(substitute(height))), main = deparse(substitute(height)),
ylab = "Frequency", ylab = "Frequency",
xlab = "Minimum Inhibitory Concentration (mg/L)", xlab = "Minimum Inhibitory Concentration (mg/L)",
colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"),
@ -299,7 +299,7 @@ fortify.mic <- function(object, ...) {
#' @importFrom graphics barplot axis mtext legend #' @importFrom graphics barplot axis mtext legend
#' @rdname plot #' @rdname plot
plot.disk <- function(x, plot.disk <- function(x,
main = paste("Disk zones of", deparse(substitute(x))), main = deparse(substitute(x)),
ylab = "Frequency", ylab = "Frequency",
xlab = "Disk diffusion diameter (mm)", xlab = "Disk diffusion diameter (mm)",
mo = NULL, mo = NULL,
@ -386,7 +386,7 @@ plot.disk <- function(x,
#' @export #' @export
#' @noRd #' @noRd
barplot.disk <- function(height, barplot.disk <- function(height,
main = paste("Disk zones of", deparse(substitute(height))), main = deparse(substitute(height)),
ylab = "Frequency", ylab = "Frequency",
xlab = "Disk diffusion diameter (mm)", xlab = "Disk diffusion diameter (mm)",
mo = NULL, mo = NULL,
@ -525,7 +525,7 @@ fortify.disk <- function(object, ...) {
plot.rsi <- function(x, plot.rsi <- function(x,
ylab = "Percentage", ylab = "Percentage",
xlab = "Antimicrobial Interpretation", xlab = "Antimicrobial Interpretation",
main = paste("Resistance Overview of", deparse(substitute(x))), main = deparse(substitute(x)),
...) { ...) {
meet_criteria(ylab, allow_class = "character", has_length = 1) meet_criteria(ylab, allow_class = "character", has_length = 1)
meet_criteria(xlab, allow_class = "character", has_length = 1) meet_criteria(xlab, allow_class = "character", has_length = 1)
@ -576,7 +576,7 @@ plot.rsi <- function(x,
#' @export #' @export
#' @noRd #' @noRd
barplot.rsi <- function(height, barplot.rsi <- function(height,
main = paste("Resistance Overview of", deparse(substitute(height))), main = deparse(substitute(height)),
xlab = "Antimicrobial Interpretation", xlab = "Antimicrobial Interpretation",
ylab = "Frequency", ylab = "Frequency",
colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"),
@ -738,7 +738,11 @@ plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_RSI, f
ab_name(ab, language = NULL, tolower = TRUE), " in ", moname) ab_name(ab, language = NULL, tolower = TRUE), " in ", moname)
guideline_txt <- "" guideline_txt <- ""
} else { } else {
guideline_txt <- paste0("(", guideline, ")") guideline_txt <- guideline
if (isTRUE(list(...)$uti)) {
guideline_txt <- paste("UTIs,", guideline_txt)
}
guideline_txt <- paste0("(", guideline_txt, ")")
} }
sub <- bquote(.(abname)~"-"~italic(.(moname))~.(guideline_txt)) sub <- bquote(.(abname)~"-"~italic(.(moname))~.(guideline_txt))
} else { } else {

View File

@ -34,7 +34,7 @@
#' @param ... ignored, only in place to allow future extensions #' @param ... ignored, only in place to allow future extensions
#' @details The base \R function [sample()] is used for generating values. #' @details The base \R function [sample()] is used for generating values.
#' #'
#' Generated values are based on the latest EUCAST guideline implemented in the [rsi_translation] data set. To create specific generated values per bug or drug, set the `mo` and/or `ab` argument. #' Generated values are based on the EUCAST `r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))` guideline as implemented in the [rsi_translation] data set. To create specific generated values per bug or drug, set the `mo` and/or `ab` argument.
#' @return class `<mic>` for [random_mic()] (see [as.mic()]) and class `<disk>` for [random_disk()] (see [as.disk()]) #' @return class `<mic>` for [random_mic()] (see [as.mic()]) and class `<disk>` for [random_disk()] (see [as.disk()])
#' @name random #' @name random
#' @rdname random #' @rdname random
@ -89,6 +89,7 @@ random_rsi <- function(size = NULL, prob_RSI = c(0.33, 0.33, 0.33), ...) {
} }
random_exec <- function(type, size, mo = NULL, ab = NULL) { random_exec <- function(type, size, mo = NULL, ab = NULL) {
check_dataset_integrity()
df <- rsi_translation %pm>% df <- rsi_translation %pm>%
pm_filter(guideline %like% "EUCAST") %pm>% pm_filter(guideline %like% "EUCAST") %pm>%
pm_arrange(pm_desc(guideline)) %pm>% pm_arrange(pm_desc(guideline)) %pm>%
@ -106,7 +107,7 @@ random_exec <- function(type, size, mo = NULL, ab = NULL) {
if (nrow(df_new) > 0) { if (nrow(df_new) > 0) {
df <- df_new df <- df_new
} else { } else {
warning_("No rows found that match mo '", mo, "', ignoring argument `mo`", call = FALSE) warning_("in `random_", tolower(type), "()`: no rows found that match mo '", mo, "', ignoring argument `mo`")
} }
} }
@ -117,7 +118,7 @@ random_exec <- function(type, size, mo = NULL, ab = NULL) {
if (nrow(df_new) > 0) { if (nrow(df_new) > 0) {
df <- df_new df <- df_new
} else { } else {
warning_("No rows found that match ab '", ab, "', ignoring argument `ab`", call = FALSE) warning_("in `random_", tolower(type), "()`: no rows found that match ab '", ab, "', ignoring argument `ab`")
} }
} }

View File

@ -153,7 +153,7 @@ resistance_predict <- function(x,
x <- dots[which(dots.names == "tbl")] x <- dots[which(dots.names == "tbl")]
} }
if ("I_as_R" %in% dots.names) { if ("I_as_R" %in% dots.names) {
warning_("`I_as_R is deprecated - use I_as_S instead.", call = FALSE) warning_("in `resistance_predict()`: I_as_R is deprecated - use I_as_S instead.")
} }
} }

399
R/rsi.R
View File

@ -33,7 +33,7 @@
#' @param ab any (vector of) text that can be coerced to a valid antimicrobial code with [as.ab()] #' @param ab any (vector of) text that can be coerced to a valid antimicrobial code with [as.ab()]
#' @param uti (Urinary Tract Infection) A vector with [logical]s (`TRUE` or `FALSE`) to specify whether a UTI specific interpretation from the guideline should be chosen. For using [as.rsi()] on a [data.frame], this can also be a column containing [logical]s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See *Examples*. #' @param uti (Urinary Tract Infection) A vector with [logical]s (`TRUE` or `FALSE`) to specify whether a UTI specific interpretation from the guideline should be chosen. For using [as.rsi()] on a [data.frame], this can also be a column containing [logical]s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See *Examples*.
#' @inheritParams first_isolate #' @inheritParams first_isolate
#' @param guideline defaults to the latest included EUCAST guideline, see *Details* for all options #' @param guideline defaults to EUCAST `r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))` (the latest implemented EUCAST guideline in the [rsi_translation] data set), supports EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`), see *Details*
#' @param conserve_capped_values a [logical] to indicate that MIC values starting with `">"` (but not `">="`) must always return "R" , and that MIC values starting with `"<"` (but not `"<="`) must always return "S" #' @param conserve_capped_values a [logical] to indicate that MIC values starting with `">"` (but not `">="`) must always return "R" , and that MIC values starting with `"<"` (but not `"<="`) must always return "S"
#' @param add_intrinsic_resistance *(only useful when using a EUCAST guideline)* a [logical] to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in *Klebsiella* species. Determination is based on the [intrinsic_resistant] data set, that itself is based on `r format_eucast_version_nr(3.3)`. #' @param add_intrinsic_resistance *(only useful when using a EUCAST guideline)* a [logical] to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in *Klebsiella* species. Determination is based on the [intrinsic_resistant] data set, that itself is based on `r format_eucast_version_nr(3.3)`.
#' @param reference_data a [data.frame] to be used for interpretation, which defaults to the [rsi_translation] data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the [rsi_translation] data set (same column names and column types). Please note that the `guideline` argument will be ignored when `reference_data` is manually set. #' @param reference_data a [data.frame] to be used for interpretation, which defaults to the [rsi_translation] data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the [rsi_translation] data set (same column names and column types). Please note that the `guideline` argument will be ignored when `reference_data` is manually set.
@ -67,7 +67,7 @@
#' #'
#' For interpreting MIC values as well as disk diffusion diameters, currently implemented guidelines are EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`). #' For interpreting MIC values as well as disk diffusion diameters, currently implemented guidelines are EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(rsi_translation, guideline %like% "CLSI")$guideline)))`).
#' #'
#' Thus, the `guideline` argument must be set to e.g., ``r paste0('"', subset(rsi_translation, guideline %like% "EUCAST")$guideline[1], '"')`` or ``r paste0('"', subset(rsi_translation, guideline %like% "CLSI")$guideline[1], '"')``. By simply using `"EUCAST"` (the default) or `"CLSI"` as input, the latest version of that guideline will automatically be selected. You can set your own data set using the `reference_data` argument. The `guideline` argument will then be ignored. #' Thus, the `guideline` argument must be set to e.g., ``r paste0('"', subset(rsi_translation, guideline %like% "EUCAST")$guideline[1], '"')`` or ``r paste0('"', subset(rsi_translation, guideline %like% "CLSI")$guideline[1], '"')``. By simply using `"EUCAST"` (the default) or `"CLSI"` as input, the latest included version of that guideline will automatically be selected. You can set your own data set using the `reference_data` argument. The `guideline` argument will then be ignored.
#' #'
#' ## After Interpretation #' ## After Interpretation
#' #'
@ -179,7 +179,7 @@
#' example_isolates %>% #' example_isolates %>%
#' mutate_if(is.rsi.eligible, as.rsi) #' mutate_if(is.rsi.eligible, as.rsi)
#' #'
#' # note: from dplyr 1.0.0 on, this will be: #' # since dplyr 1.0.0, this can also be:
#' # example_isolates %>% #' # example_isolates %>%
#' # mutate(across(where(is.rsi.eligible), as.rsi)) #' # mutate(across(where(is.rsi.eligible), as.rsi))
#' } #' }
@ -189,7 +189,7 @@ as.rsi <- function(x, ...) {
} }
#' @rdname as.rsi #' @rdname as.rsi
#' @details `NA_rsi_` is a missing value of the new `<rsi>` class. #' @details `NA_rsi_` is a missing value of the new `<rsi>` class, analogous to e.g. base \R's [`NA_character_`][base::NA].
#' @export #' @export
NA_rsi_ <- set_clean_class(factor(NA, levels = c("S", "I", "R"), ordered = TRUE), NA_rsi_ <- set_clean_class(factor(NA, levels = c("S", "I", "R"), ordered = TRUE),
new_class = c("rsi", "ordered", "factor")) new_class = c("rsi", "ordered", "factor"))
@ -233,9 +233,9 @@ is.rsi.eligible <- function(x, threshold = 0.05) {
} else if (!any(c("R", "S", "I") %in% x, na.rm = TRUE) & !all(is.na(x))) { } else if (!any(c("R", "S", "I") %in% x, na.rm = TRUE) & !all(is.na(x))) {
return(FALSE) return(FALSE)
} else { } else {
x <- x[!is.na(x) & !is.null(x) & x != ""] x <- x[!is.na(x) & !is.null(x) & !x %in% c("", "-", "NULL")]
if (length(x) == 0) { if (length(x) == 0) {
# no other values than NA or "" # no other values than empty
cur_col <- get_current_column() cur_col <- get_current_column()
if (!is.null(cur_col)) { if (!is.null(cur_col)) {
ab <- suppressWarnings(as.ab(cur_col, fast_mode = TRUE, info = FALSE)) ab <- suppressWarnings(as.ab(cur_col, fast_mode = TRUE, info = FALSE))
@ -257,7 +257,7 @@ is.rsi.eligible <- function(x, threshold = 0.05) {
} }
#' @export #' @export
# extra param: warn (never throw warning) # extra param: warn (logical, to never throw a warning)
as.rsi.default <- function(x, ...) { as.rsi.default <- function(x, ...) {
if (is.rsi(x)) { if (is.rsi(x)) {
return(x) return(x)
@ -278,22 +278,23 @@ as.rsi.default <- function(x, ...) {
x[x.bak == 2] <- "I" x[x.bak == 2] <- "I"
x[x.bak == 3] <- "R" x[x.bak == 3] <- "R"
} }
} else if (!all(is.na(x)) && !identical(levels(x), c("R", "S", "I")) && !all(x %in% c("R", "S", "I", NA))) { } else if (!all(is.na(x)) && !identical(levels(x), c("R", "S", "I")) && !all(x %in% c("R", "S", "I", NA))) {
if (all(x %unlike% "(R|S|I)", na.rm = TRUE)) { if (all(x %unlike% "(R|S|I)", na.rm = TRUE)) {
# check if they are actually MICs or disks # check if they are actually MICs or disks
if (all_valid_mics(x)) { if (all_valid_mics(x)) {
warning_("The input seems to contain MIC values. You can transform them with `as.mic()` before running `as.rsi()` to interpret them.", call = FALSE) warning_("in `as.rsi()`: the input seems to contain MIC values. You can transform them with `as.mic()` before running `as.rsi()` to interpret them.")
} else if (all_valid_disks(x)) { } else if (all_valid_disks(x)) {
warning_("The input seems to contain disk diffusion values. You can transform them with `as.disk()` before running `as.rsi()` to interpret them.", call = FALSE) warning_("in `as.rsi()`: the input seems to contain disk diffusion values. You can transform them with `as.disk()` before running `as.rsi()` to interpret them.")
} }
} }
# trim leading and trailing spaces, new lines, etc. # trim leading and trailing spaces, new lines, etc.
x <- trimws2(as.character(unlist(x))) x <- trimws2(as.character(unlist(x)))
x[x %in% c(NA, "", "-", "NULL")] <- NA_character_
x.bak <- x x.bak <- x
na_before <- length(x[is.na(x) | x == ""]) na_before <- length(x[is.na(x)])
# correct for translations # correct for translations
trans_R <- unlist(TRANSLATIONS[which(TRANSLATIONS$pattern == "Resistant"), trans_R <- unlist(TRANSLATIONS[which(TRANSLATIONS$pattern == "Resistant"),
@ -310,11 +311,15 @@ as.rsi.default <- function(x, ...) {
x[x %like% "([^a-z]|^)sus(cep(tible)?)?"] <- "S" x[x %like% "([^a-z]|^)sus(cep(tible)?)?"] <- "S"
x[x %like% "([^a-z]|^)int(er(mediate)?)?|incr.*exp"] <- "I" x[x %like% "([^a-z]|^)int(er(mediate)?)?|incr.*exp"] <- "I"
# remove other invalid characters # remove other invalid characters
x <- gsub("[^rsiRSIHi]+", "", x, perl = TRUE)
# some labs now report "H" instead of "I" to not interfere with EUCAST prior to 2019
x <- gsub("H", "I", x, ignore.case = TRUE)
# set to capitals # set to capitals
x <- toupper(x) x <- toupper(x)
x <- gsub("[^RSIHDU]+", "", x, perl = TRUE)
# some labs now report "H" instead of "I" to not interfere with EUCAST prior to 2019
x <- gsub("^H$", "I", x, perl = TRUE)
# and MIPS uses D for Dose-dependent (which is I, but it will throw a note)
x <- gsub("^D$", "I", x, perl = TRUE)
# and MIPS uses U for "susceptible urine"
x <- gsub("^U$", "S", x, perl = TRUE)
# in cases of "S;S" keep S, but in case of "S;I" make it NA # in cases of "S;S" keep S, but in case of "S;I" make it NA
x <- gsub("^S+$", "S", x) x <- gsub("^S+$", "S", x)
x <- gsub("^I+$", "I", x) x <- gsub("^I+$", "I", x)
@ -328,11 +333,20 @@ as.rsi.default <- function(x, ...) {
unique() %pm>% unique() %pm>%
sort() %pm>% sort() %pm>%
vector_and(quotes = TRUE) vector_and(quotes = TRUE)
warning_(na_after - na_before, " results truncated (", warning_("in `as.rsi()`: ", na_after - na_before, " results truncated (",
round(((na_after - na_before) / length(x)) * 100), round(((na_after - na_before) / length(x)) * 100),
"%) that were invalid antimicrobial interpretations: ", "%) that were invalid antimicrobial interpretations: ",
list_missing, call = FALSE) list_missing, call = FALSE)
} }
if (any(toupper(x.bak[!is.na(x.bak)]) == "U") && message_not_thrown_before("as.rsi", "U")) {
warning_("in `as.rsi()`: 'U' was interpreted as 'S', following some laboratory systems")
}
if (any(toupper(x.bak[!is.na(x.bak)]) == "D") && message_not_thrown_before("as.rsi", "D")) {
warning_("in `as.rsi()`: 'D' (dose-dependent) was interpreted as 'I', following some laboratory systems")
}
if (any(toupper(x.bak[!is.na(x.bak)]) == "H") && message_not_thrown_before("as.rsi", "H")) {
warning_("in `as.rsi()`: 'H' was interpreted as 'I', following some laboratory systems")
}
} }
} }
@ -351,89 +365,17 @@ as.rsi.mic <- function(x,
add_intrinsic_resistance = FALSE, add_intrinsic_resistance = FALSE,
reference_data = AMR::rsi_translation, reference_data = AMR::rsi_translation,
...) { ...) {
meet_criteria(x) as_rsi_method(method_short = "mic",
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) method_long = "MIC values",
meet_criteria(ab, allow_class = c("ab", "character")) x = x,
meet_criteria(guideline, allow_class = "character", has_length = 1) mo = mo,
meet_criteria(uti, allow_class = "logical", has_length = c(1, length(x))) ab = ab,
meet_criteria(conserve_capped_values, allow_class = "logical", has_length = 1) guideline = guideline,
meet_criteria(add_intrinsic_resistance, allow_class = "logical", has_length = 1) uti = uti,
meet_criteria(reference_data, allow_class = "data.frame") conserve_capped_values = conserve_capped_values,
check_reference_data(reference_data) add_intrinsic_resistance = add_intrinsic_resistance,
reference_data = reference_data,
# for dplyr's across() ...)
cur_column_dplyr <- import_fn("cur_column", "dplyr", error_on_fail = FALSE)
if (!is.null(cur_column_dplyr) && tryCatch(is.data.frame(get_current_data("ab", call = 0)), error = function(e) FALSE)) {
# try to get current column, which will only be available when in across()
ab <- tryCatch(cur_column_dplyr(),
error = function(e) ab)
}
# for auto-determining mo
mo_var_found <- ""
if (is.null(mo)) {
tryCatch({
df <- get_current_data(arg_name = "mo", call = -3) # will return an error if not found
mo <- NULL
try({
mo <- suppressMessages(search_type_in_df(df, "mo"))
}, silent = TRUE)
if (!is.null(df) && !is.null(mo) && is.data.frame(df)) {
mo_var_found <- paste0(" based on column '", font_bold(mo), "'")
mo <- df[, mo, drop = TRUE]
}
}, error = function(e)
stop_('No information was supplied about the microorganisms (missing argument `mo`). See ?as.rsi.\n\n',
"To transform certain columns with e.g. mutate_at(), use `data %>% mutate_at(vars(...), as.rsi, mo = .$x)`, where x is your column with microorganisms.\n",
"To tranform all disk diffusion zones in a data set, use `data %>% as.rsi()` or data %>% mutate_if(is.disk, as.rsi).", call = FALSE)
)
}
if (length(ab) == 1 && ab %like% "as.mic") {
stop_('No unambiguous name was supplied about the antibiotic (argument `ab`). See ?as.rsi.', call = FALSE)
}
ab_coerced <- suppressWarnings(as.ab(ab))
mo_coerced <- suppressWarnings(as.mo(mo))
guideline_coerced <- get_guideline(guideline, reference_data)
if (is.na(ab_coerced)) {
message_("Returning NAs for unknown drug: '", font_bold(ab),
"'. Rename this column to a drug name or code, and check the output with `as.ab()`.",
add_fn = font_red,
as_note = FALSE)
return(as.rsi(rep(NA, length(x))))
}
if (length(mo_coerced) == 1) {
mo_coerced <- rep(mo_coerced, length(x))
}
if (length(uti) == 1) {
uti <- rep(uti, length(x))
}
agent_formatted <- paste0("'", font_bold(ab), "'")
agent_name <- ab_name(ab_coerced, tolower = TRUE, language = NULL)
if (generalise_antibiotic_name(ab) != generalise_antibiotic_name(agent_name)) {
agent_formatted <- paste0(agent_formatted, " (", ab_coerced, ", ", agent_name, ")")
}
message_("=> Interpreting MIC values of ", ifelse(isTRUE(list(...)$is_data.frame), "column ", ""),
agent_formatted,
mo_var_found,
" according to ", ifelse(identical(reference_data, AMR::rsi_translation),
font_bold(guideline_coerced),
"manually defined 'reference_data'"),
"... ",
appendLF = FALSE,
as_note = FALSE)
result <- exec_as.rsi(method = "mic",
x = x,
mo = mo_coerced,
ab = ab_coerced,
guideline = guideline_coerced,
uti = uti,
conserve_capped_values = conserve_capped_values,
add_intrinsic_resistance = add_intrinsic_resistance,
reference_data = reference_data) # exec_as.rsi will return message 'OK'
result
} }
#' @rdname as.rsi #' @rdname as.rsi
@ -446,88 +388,17 @@ as.rsi.disk <- function(x,
add_intrinsic_resistance = FALSE, add_intrinsic_resistance = FALSE,
reference_data = AMR::rsi_translation, reference_data = AMR::rsi_translation,
...) { ...) {
meet_criteria(x) as_rsi_method(method_short = "disk",
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE) method_long = "disk diffusion zones",
meet_criteria(ab, allow_class = c("ab", "character")) x = x,
meet_criteria(guideline, allow_class = "character", has_length = 1) mo = mo,
meet_criteria(uti, allow_class = "logical", has_length = c(1, length(x))) ab = ab,
meet_criteria(add_intrinsic_resistance, allow_class = "logical", has_length = 1) guideline = guideline,
meet_criteria(reference_data, allow_class = "data.frame") uti = uti,
check_reference_data(reference_data) conserve_capped_values = FALSE,
add_intrinsic_resistance = add_intrinsic_resistance,
# for dplyr's across() reference_data = reference_data,
cur_column_dplyr <- import_fn("cur_column", "dplyr", error_on_fail = FALSE) ...)
if (!is.null(cur_column_dplyr) && tryCatch(is.data.frame(get_current_data("ab", call = 0)), error = function(e) FALSE)) {
# try to get current column, which will only be available when in across()
ab <- tryCatch(cur_column_dplyr(),
error = function(e) ab)
}
# for auto-determining mo
mo_var_found <- ""
if (is.null(mo)) {
tryCatch({
df <- get_current_data(arg_name = "mo", call = -3) # will return an error if not found
mo <- NULL
try({
mo <- suppressMessages(search_type_in_df(df, "mo"))
}, silent = TRUE)
if (!is.null(df) && !is.null(mo) && is.data.frame(df)) {
mo_var_found <- paste0(" based on column '", font_bold(mo), "'")
mo <- df[, mo, drop = TRUE]
}
}, error = function(e)
stop_('No information was supplied about the microorganisms (missing argument `mo`). See ?as.rsi.\n\n',
"To transform certain columns with e.g. mutate_at(), use `data %>% mutate_at(vars(...), as.rsi, mo = .$x)`, where x is your column with microorganisms.\n",
"To tranform all disk diffusion zones in a data set, use `data %>% as.rsi()` or data %>% mutate_if(is.disk, as.rsi).", call = FALSE)
)
}
if (length(ab) == 1 && ab %like% "as.disk") {
stop_('No unambiguous name was supplied about the antibiotic (argument `ab`). See ?as.rsi.', call = FALSE)
}
ab_coerced <- suppressWarnings(as.ab(ab))
mo_coerced <- suppressWarnings(as.mo(mo))
guideline_coerced <- get_guideline(guideline, reference_data)
if (is.na(ab_coerced)) {
message_("Returning NAs for unknown drug: '", font_bold(ab),
"'. Rename this column to a drug name or code, and check the output with `as.ab()`.",
add_fn = font_red,
as_note = FALSE)
return(as.rsi(rep(NA, length(x))))
}
if (length(mo_coerced) == 1) {
mo_coerced <- rep(mo_coerced, length(x))
}
if (length(uti) == 1) {
uti <- rep(uti, length(x))
}
agent_formatted <- paste0("'", font_bold(ab), "'")
agent_name <- ab_name(ab_coerced, tolower = TRUE, language = NULL)
if (generalise_antibiotic_name(ab) != generalise_antibiotic_name(agent_name)) {
agent_formatted <- paste0(agent_formatted, " (", ab_coerced, ", ", agent_name, ")")
}
message_("=> Interpreting disk zones of ", ifelse(isTRUE(list(...)$is_data.frame), "column ", ""),
agent_formatted,
mo_var_found,
" according to ", ifelse(identical(reference_data, AMR::rsi_translation),
font_bold(guideline_coerced),
"manually defined 'reference_data'"),
"... ",
appendLF = FALSE,
as_note = FALSE)
result <- exec_as.rsi(method = "disk",
x = x,
mo = mo_coerced,
ab = ab_coerced,
guideline = guideline_coerced,
uti = uti,
conserve_capped_values = FALSE,
add_intrinsic_resistance = add_intrinsic_resistance,
reference_data = reference_data) # exec_as.rsi will return message 'OK'
result
} }
#' @rdname as.rsi #' @rdname as.rsi
@ -547,7 +418,7 @@ as.rsi.data.frame <- function(x,
meet_criteria(conserve_capped_values, allow_class = "logical", has_length = 1) meet_criteria(conserve_capped_values, allow_class = "logical", has_length = 1)
meet_criteria(add_intrinsic_resistance, allow_class = "logical", has_length = 1) meet_criteria(add_intrinsic_resistance, allow_class = "logical", has_length = 1)
meet_criteria(reference_data, allow_class = "data.frame") meet_criteria(reference_data, allow_class = "data.frame")
x.bak <- x x.bak <- x
for (i in seq_len(ncol(x))) { for (i in seq_len(ncol(x))) {
# don't keep factors, overwriting them is hard # don't keep factors, overwriting them is hard
@ -561,7 +432,7 @@ as.rsi.data.frame <- function(x,
if (is.null(col_mo)) { if (is.null(col_mo)) {
col_mo <- search_type_in_df(x = x, type = "mo", info = FALSE) col_mo <- search_type_in_df(x = x, type = "mo", info = FALSE)
} }
# -- UTIs # -- UTIs
col_uti <- uti col_uti <- uti
if (is.null(col_uti)) { if (is.null(col_uti)) {
@ -602,7 +473,7 @@ as.rsi.data.frame <- function(x,
uti <- FALSE uti <- FALSE
} }
} }
i <- 0 i <- 0
if (tryCatch(length(list(...)) > 0, error = function(e) TRUE)) { if (tryCatch(length(list(...)) > 0, error = function(e) TRUE)) {
sel <- colnames(pm_select(x, ...)) sel <- colnames(pm_select(x, ...))
@ -612,7 +483,7 @@ as.rsi.data.frame <- function(x,
if (!is.null(col_mo)) { if (!is.null(col_mo)) {
sel <- sel[sel != col_mo] sel <- sel[sel != col_mo]
} }
ab_cols <- colnames(x)[vapply(FUN.VALUE = logical(1), x, function(y) { ab_cols <- colnames(x)[vapply(FUN.VALUE = logical(1), x, function(y) {
i <<- i + 1 i <<- i + 1
check <- is.mic(y) | is.disk(y) check <- is.mic(y) | is.disk(y)
@ -635,7 +506,7 @@ as.rsi.data.frame <- function(x,
return(FALSE) return(FALSE)
} }
})] })]
stop_if(length(ab_cols) == 0, stop_if(length(ab_cols) == 0,
"no columns with MIC values, disk zones or antibiotic column names found in this data set. Use as.mic() or as.disk() to transform antimicrobial columns.") "no columns with MIC values, disk zones or antibiotic column names found in this data set. Use as.mic() or as.disk() to transform antimicrobial columns.")
# set type per column # set type per column
@ -654,7 +525,7 @@ as.rsi.data.frame <- function(x,
} }
x_mo <- as.mo(x[, col_mo, drop = TRUE]) x_mo <- as.mo(x[, col_mo, drop = TRUE])
} }
for (i in seq_len(length(ab_cols))) { for (i in seq_len(length(ab_cols))) {
if (types[i] == "mic") { if (types[i] == "mic") {
x[, ab_cols[i]] <- as.rsi(x = x %pm>% x[, ab_cols[i]] <- as.rsi(x = x %pm>%
@ -732,6 +603,105 @@ get_guideline <- function(guideline, reference_data) {
guideline_param guideline_param
} }
as_rsi_method <- function(method_short = "mic",
method_long = "MIC values",
x = x,
mo = NULL,
ab = deparse(substitute(x)),
guideline = "EUCAST",
uti = FALSE,
conserve_capped_values = FALSE,
add_intrinsic_resistance = FALSE,
reference_data = AMR::rsi_translation,
...) {
meet_criteria(x)
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE)
meet_criteria(ab, allow_class = c("ab", "character"))
meet_criteria(guideline, allow_class = "character", has_length = 1)
meet_criteria(uti, allow_class = "logical", has_length = c(1, length(x)))
meet_criteria(conserve_capped_values, allow_class = "logical", has_length = 1)
meet_criteria(add_intrinsic_resistance, allow_class = "logical", has_length = 1)
meet_criteria(reference_data, allow_class = "data.frame")
check_reference_data(reference_data)
# for dplyr's across()
cur_column_dplyr <- import_fn("cur_column", "dplyr", error_on_fail = FALSE)
if (!is.null(cur_column_dplyr) && tryCatch(is.data.frame(get_current_data("ab", call = 0)), error = function(e) FALSE)) {
# try to get current column, which will only be available when in across()
ab <- tryCatch(cur_column_dplyr(),
error = function(e) ab)
}
# for auto-determining mo
mo_var_found <- ""
if (is.null(mo)) {
tryCatch({
df <- get_current_data(arg_name = "mo", call = -3) # will return an error if not found
mo <- NULL
try({
mo <- suppressMessages(search_type_in_df(df, "mo"))
}, silent = TRUE)
if (!is.null(df) && !is.null(mo) && is.data.frame(df)) {
mo_var_found <- paste0(" based on column '", font_bold(mo), "'")
mo <- df[, mo, drop = TRUE]
}
}, error = function(e) {
mo <- NULL
})
}
if (is.null(mo)) {
stop_("No information was supplied about the microorganisms (missing argument `mo` and no column of class <mo> found). See ?as.rsi.\n\n",
"To transform certain columns with e.g. mutate(), use `data %>% mutate(across(..., as.rsi, mo = x))`, where x is your column with microorganisms.\n",
"To tranform all ", method_long, " in a data set, use `data %>% as.rsi()` or `data %>% mutate(across(where(is.", method_short, "), as.rsi))`.", call = FALSE)
}
if (length(ab) == 1 && ab %like% paste0("as.", method_short)) {
stop_('No unambiguous name was supplied about the antibiotic (argument `ab`). See ?as.rsi.', call = FALSE)
}
ab_coerced <- suppressWarnings(as.ab(ab))
mo_coerced <- suppressWarnings(as.mo(mo))
guideline_coerced <- get_guideline(guideline, reference_data)
if (is.na(ab_coerced)) {
message_("Returning NAs for unknown drug: '", font_bold(ab),
"'. Rename this column to a drug name or code, and check the output with `as.ab()`.",
add_fn = font_red,
as_note = FALSE)
return(as.rsi(rep(NA, length(x))))
}
if (length(mo_coerced) == 1) {
mo_coerced <- rep(mo_coerced, length(x))
}
if (length(uti) == 1) {
uti <- rep(uti, length(x))
}
agent_formatted <- paste0("'", font_bold(ab), "'")
agent_name <- ab_name(ab_coerced, tolower = TRUE, language = NULL)
if (generalise_antibiotic_name(ab) != generalise_antibiotic_name(agent_name)) {
agent_formatted <- paste0(agent_formatted, " (", ab_coerced, ", ", agent_name, ")")
}
message_("=> Interpreting ", method_long, " of ", ifelse(isTRUE(list(...)$is_data.frame), "column ", ""),
agent_formatted,
mo_var_found,
" according to ", ifelse(identical(reference_data, AMR::rsi_translation),
font_bold(guideline_coerced),
"manually defined 'reference_data'"),
"... ",
appendLF = FALSE,
as_note = FALSE)
result <- exec_as.rsi(method = method_short,
x = x,
mo = mo_coerced,
ab = ab_coerced,
guideline = guideline_coerced,
uti = uti,
conserve_capped_values = conserve_capped_values,
add_intrinsic_resistance = add_intrinsic_resistance,
reference_data = reference_data) # exec_as.rsi will return message 'OK'
result
}
exec_as.rsi <- function(method, exec_as.rsi <- function(method,
x, x,
mo, mo,
@ -744,7 +714,7 @@ exec_as.rsi <- function(method,
metadata_mo <- get_mo_failures_uncertainties_renamed() metadata_mo <- get_mo_failures_uncertainties_renamed()
x_bak <- data.frame(x_mo = paste0(x, mo), stringsAsFactors = FALSE) x_bak <- data.frame(x_mo = paste0(x, mo), stringsAsFactors = FALSE)
df <- unique(data.frame(x, mo), stringsAsFactors = FALSE) df <- unique(data.frame(x, mo, x_mo = paste0(x, mo), stringsAsFactors = FALSE))
x <- df$x x <- df$x
mo <- df$mo mo <- df$mo
@ -754,7 +724,7 @@ exec_as.rsi <- function(method,
x <- as.disk(x) # when as.rsi.disk is called directly x <- as.disk(x) # when as.rsi.disk is called directly
} }
warned <- FALSE rise_warning <- FALSE
method_param <- toupper(method) method_param <- toupper(method)
genera <- mo_genus(mo, language = NULL) genera <- mo_genus(mo, language = NULL)
@ -799,13 +769,6 @@ exec_as.rsi <- function(method,
lookup_lancefield <- paste(mo_lancefield, ab) lookup_lancefield <- paste(mo_lancefield, ab)
lookup_other <- paste(mo_other, ab) lookup_other <- paste(mo_other, ab)
if (length(unique(paste(trans$mo, trans$ab))) == length(unique(paste(trans$mo, trans$ab, trans$uti))) &&
any(trans$uti == TRUE, na.rm = TRUE) && all(uti == FALSE)) {
message_("WARNING.", add_fn = list(font_yellow, font_bold), as_note = FALSE)
warning_("Introducing NA: interpretation of ", font_bold(ab_name(ab, tolower = TRUE)), " for some microorganisms is only available for (uncomplicated) urinary tract infections (UTI). Use argument `uti` to set which isolates are from urine. See ?as.rsi.", call = FALSE)
warned <- TRUE
}
any_is_intrinsic_resistant <- FALSE any_is_intrinsic_resistant <- FALSE
for (i in seq_len(length(x))) { for (i in seq_len(length(x))) {
@ -815,7 +778,7 @@ exec_as.rsi <- function(method,
if (isTRUE(add_intrinsic_resistance) & is_intrinsic_r) { if (isTRUE(add_intrinsic_resistance) & is_intrinsic_r) {
if (guideline_coerced %unlike% "EUCAST") { if (guideline_coerced %unlike% "EUCAST") {
if (message_not_thrown_before("as.rsi", "msg2")) { if (message_not_thrown_before("as.rsi", "msg2")) {
warning_("Using 'add_intrinsic_resistance' is only useful when using EUCAST guidelines, since the rules for intrinsic resistance are based on EUCAST.", call = FALSE) warning_("in `as.rsi()`: using 'add_intrinsic_resistance' is only useful when using EUCAST guidelines, since the rules for intrinsic resistance are based on EUCAST.")
} }
} else { } else {
new_rsi[i] <- "R" new_rsi[i] <- "R"
@ -824,7 +787,7 @@ exec_as.rsi <- function(method,
} }
get_record <- trans %pm>% get_record <- trans %pm>%
# no subsetting to UTI for now # no subsetting to UTI here
subset(lookup %in% c(lookup_mo[i], subset(lookup %in% c(lookup_mo[i],
lookup_genus[i], lookup_genus[i],
lookup_family[i], lookup_family[i],
@ -833,6 +796,11 @@ exec_as.rsi <- function(method,
lookup_lancefield[i], lookup_lancefield[i],
lookup_other[i])) lookup_other[i]))
if (any(get_record$uti == TRUE, na.rm = TRUE) && message_not_thrown_before("as.rsi", "msg3", ab)) {
warning_("in `as.rsi()`: interpretation of ", font_bold(ab_name(ab, tolower = TRUE)), " is only available for (uncomplicated) urinary tract infections (UTI) for some microorganisms. Use argument `uti` to set which isolates are from urine. See ?as.rsi.")
rise_warning <- TRUE
}
if (isTRUE(uti[i])) { if (isTRUE(uti[i])) {
get_record <- get_record %pm>% get_record <- get_record %pm>%
# be as specific as possible (i.e. prefer species over genus): # be as specific as possible (i.e. prefer species over genus):
@ -843,25 +811,27 @@ exec_as.rsi <- function(method,
pm_filter(uti == FALSE) %pm>% # 'uti' is a column in rsi_translation pm_filter(uti == FALSE) %pm>% # 'uti' is a column in rsi_translation
pm_arrange(rank_index) pm_arrange(rank_index)
} }
get_record <- get_record[1L, , drop = FALSE] get_record <- get_record[1L, , drop = FALSE]
if (NROW(get_record) > 0) { if (NROW(get_record) > 0) {
if (is.na(x[i]) | (is.na(get_record$breakpoint_S) & is.na(get_record$breakpoint_R))) { if (is.na(x[i]) | (is.na(get_record$breakpoint_S) & is.na(get_record$breakpoint_R))) {
new_rsi[i] <- NA_character_ new_rsi[i] <- NA_character_
} else if (method == "mic") { } else if (method == "mic") {
new_rsi[i] <- quick_case_when(isTRUE(conserve_capped_values) & x[i] %like% "^<[0-9]" ~ "S", new_rsi[i] <- quick_case_when(isTRUE(conserve_capped_values) & isTRUE(x[i] %like% "^<[0-9]") ~ "S",
isTRUE(conserve_capped_values) & x[i] %like% "^>[0-9]" ~ "R", isTRUE(conserve_capped_values) & isTRUE(x[i] %like% "^>[0-9]") ~ "R",
# these basically call `<=.mic()` and `>=.mic()`: # these basically call `<=.mic()` and `>=.mic()`:
x[i] <= get_record$breakpoint_S ~ "S", isTRUE(x[i] <= get_record$breakpoint_S) ~ "S",
x[i] >= get_record$breakpoint_R ~ "R", guideline_coerced %like% "EUCAST" & isTRUE(x[i] > get_record$breakpoint_R) ~ "R",
guideline_coerced %like% "CLSI" & isTRUE(x[i] >= get_record$breakpoint_R) ~ "R",
# return "I" when not match the bottom or top # return "I" when not match the bottom or top
!is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I", !is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I",
# and NA otherwise # and NA otherwise
TRUE ~ NA_character_) TRUE ~ NA_character_)
} else if (method == "disk") { } else if (method == "disk") {
new_rsi[i] <- quick_case_when(isTRUE(as.double(x[i]) >= as.double(get_record$breakpoint_S)) ~ "S", new_rsi[i] <- quick_case_when(isTRUE(as.double(x[i]) >= as.double(get_record$breakpoint_S)) ~ "S",
isTRUE(as.double(x[i]) <= as.double(get_record$breakpoint_R)) ~ "R", guideline_coerced %like% "EUCAST" & isTRUE(as.double(x[i]) < as.double(get_record$breakpoint_R)) ~ "R",
guideline_coerced %like% "CLSI" & isTRUE(as.double(x[i]) <= as.double(get_record$breakpoint_R)) ~ "R",
# return "I" when not match the bottom or top # return "I" when not match the bottom or top
!is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I", !is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I",
# and NA otherwise # and NA otherwise
@ -872,20 +842,21 @@ exec_as.rsi <- function(method,
if (any_is_intrinsic_resistant & guideline_coerced %like% "EUCAST" & !isTRUE(add_intrinsic_resistance)) { if (any_is_intrinsic_resistant & guideline_coerced %like% "EUCAST" & !isTRUE(add_intrinsic_resistance)) {
# found some intrinsic resistance, but was not applied # found some intrinsic resistance, but was not applied
message_("WARNING.", add_fn = list(font_yellow, font_bold), as_note = FALSE) if (message_not_thrown_before("as.rsi", "msg4")) {
if (message_not_thrown_before("as.rsi", "msg3")) { warning_("in `as.rsi()`: found intrinsic resistance in some bug/drug combinations, although it was not applied.\nUse `as.rsi(..., add_intrinsic_resistance = TRUE)` to apply it.")
warning_("Found intrinsic resistance in some bug/drug combinations, although it was not applied.\nUse `as.rsi(..., add_intrinsic_resistance = TRUE)` to apply it.", call = FALSE)
} }
warned <- TRUE rise_warning <- TRUE
} }
new_rsi <- x_bak %pm>% new_rsi <- x_bak %pm>%
pm_left_join(data.frame(x_mo = paste0(df$x, df$mo), new_rsi, pm_left_join(data.frame(x_mo = paste0(x, mo), new_rsi,
stringsAsFactors = FALSE), stringsAsFactors = FALSE),
by = "x_mo") %pm>% by = "x_mo") %pm>%
pm_pull(new_rsi) pm_pull(new_rsi)
if (warned == FALSE) { if (isTRUE(rise_warning)) {
message_("WARNING.", add_fn = list(font_yellow, font_bold), as_note = FALSE)
} else {
message_(" OK.", add_fn = list(font_green, font_bold), as_note = FALSE) message_(" OK.", add_fn = list(font_green, font_bold), as_note = FALSE)
} }
@ -937,13 +908,13 @@ freq.rsi <- function(x, ...) {
.add_header = list( .add_header = list(
Drug = paste0(ab_name(ab, language = NULL), " (", ab, ", ", paste(ab_atc(ab), collapse = "/"), ")"), Drug = paste0(ab_name(ab, language = NULL), " (", ab, ", ", paste(ab_atc(ab), collapse = "/"), ")"),
`Drug group` = ab_group(ab, language = NULL), `Drug group` = ab_group(ab, language = NULL),
`%SI` = percentage(susceptibility(x, minimum = 0, as_percent = FALSE), `%SI` = trimws(percentage(susceptibility(x, minimum = 0, as_percent = FALSE),
digits = digits))) digits = digits))))
} else { } else {
cleaner::freq.default(x = x, ..., cleaner::freq.default(x = x, ...,
.add_header = list( .add_header = list(
`%SI` = percentage(susceptibility(x, minimum = 0, as_percent = FALSE), `%SI` = trimws(percentage(susceptibility(x, minimum = 0, as_percent = FALSE),
digits = digits))) digits = digits))))
} }
} }

View File

@ -95,7 +95,7 @@ rsi_calc <- function(...,
} }
if (is.null(x)) { if (is.null(x)) {
warning_("argument is NULL (check if columns exist): returning NA", call = FALSE) warning_("argument is NULL (check if columns exist): returning NA")
if (as_percent == TRUE) { if (as_percent == TRUE) {
return(NA_character_) return(NA_character_)
} else { } else {

Binary file not shown.

View File

@ -193,7 +193,7 @@ translate_AMR <- function(from,
any_form_in_patterns <- tryCatch( any_form_in_patterns <- tryCatch(
any(from_unique %like% paste0("(", paste(gsub(" +\\(.*", "", df_trans$pattern), collapse = "|"), ")")), any(from_unique %like% paste0("(", paste(gsub(" +\\(.*", "", df_trans$pattern), collapse = "|"), ")")),
error = function(e) { error = function(e) {
warning_("Translation not possible. Please open an issue on GitHub (https://github.com/msberends/AMR/issues).", call = FALSE) warning_("Translation not possible. Please open an issue on GitHub (https://github.com/msberends/AMR/issues).")
return(FALSE) return(FALSE)
}) })

View File

@ -27,7 +27,7 @@
#' #'
#' All antimicrobial drugs and their official names, ATC codes, ATC groups and defined daily dose (DDD) are included in this package, using the WHO Collaborating Centre for Drug Statistics Methodology. #' All antimicrobial drugs and their official names, ATC codes, ATC groups and defined daily dose (DDD) are included in this package, using the WHO Collaborating Centre for Drug Statistics Methodology.
#' @section WHOCC: #' @section WHOCC:
#' \if{html}{\figure{logo_who.png}{options: height=60px style=margin-bottom:5px} \cr} #' \if{html}{\figure{logo_who.png}{options: height="60" style=margin-bottom:"5"} \cr}
#' This package contains **all ~550 antibiotic, antimycotic and antiviral drugs** and their Anatomical Therapeutic Chemical (ATC) codes, ATC groups and Defined Daily Dose (DDD) from the World Health Organization Collaborating Centre for Drug Statistics Methodology (WHOCC, <https://www.whocc.no>) and the Pharmaceuticals Community Register of the European Commission (<https://ec.europa.eu/health/documents/community-register/html/reg_hum_atc.htm>). #' This package contains **all ~550 antibiotic, antimycotic and antiviral drugs** and their Anatomical Therapeutic Chemical (ATC) codes, ATC groups and Defined Daily Dose (DDD) from the World Health Organization Collaborating Centre for Drug Statistics Methodology (WHOCC, <https://www.whocc.no>) and the Pharmaceuticals Community Register of the European Commission (<https://ec.europa.eu/health/documents/community-register/html/reg_hum_atc.htm>).
#' #'
#' These have become the gold standard for international drug utilisation monitoring and research. #' These have become the gold standard for international drug utilisation monitoring and research.

28
R/zzz.R
View File

@ -26,6 +26,11 @@
# set up package environment, used by numerous AMR functions # set up package environment, used by numerous AMR functions
pkg_env <- new.env(hash = FALSE) pkg_env <- new.env(hash = FALSE)
pkg_env$mo_failed <- character(0) pkg_env$mo_failed <- character(0)
pkg_env$mo_field_abbreviations <- c("AIEC", "ATEC", "BORSA", "CRSM", "DAEC", "EAEC",
"EHEC", "EIEC", "EPEC", "ETEC", "GISA", "MRPA",
"MRSA", "MRSE", "MSSA", "MSSE", "NMEC", "PISP",
"PRSP", "STEC", "UPEC", "VISA", "VISP", "VRE",
"VRSA", "VRSP")
# determine info icon for messages # determine info icon for messages
utf8_supported <- isTRUE(base::l10n_info()$`UTF-8`) utf8_supported <- isTRUE(base::l10n_info()$`UTF-8`)
@ -111,21 +116,7 @@ if (utf8_supported && !is_latex) {
# Helper functions -------------------------------------------------------- # Helper functions --------------------------------------------------------
create_AB_lookup <- function() { create_AB_lookup <- function() {
AB_lookup <- AMR::antibiotics cbind(AMR::antibiotics, AB_LOOKUP)
AB_lookup$generalised_name <- generalise_antibiotic_name(AB_lookup$name)
AB_lookup$generalised_synonyms <- lapply(AB_lookup$synonyms, generalise_antibiotic_name)
AB_lookup$generalised_abbreviations <- lapply(AB_lookup$abbreviations, generalise_antibiotic_name)
AB_lookup$generalised_loinc <- lapply(AB_lookup$loinc, generalise_antibiotic_name)
AB_lookup$generalised_all <- unname(lapply(as.list(as.data.frame(t(AB_lookup[,
c("ab", "atc", "cid", "name",
colnames(AB_lookup)[colnames(AB_lookup) %like% "generalised"]),
drop = FALSE]),
stringsAsFactors = FALSE)),
function(x) {
x <- generalise_antibiotic_name(unname(unlist(x)))
x[x != ""]
}))
AB_lookup
} }
create_MO_lookup <- function() { create_MO_lookup <- function() {
@ -140,12 +131,7 @@ create_MO_lookup <- function() {
MO_lookup[which(is.na(MO_lookup$kingdom_index)), "kingdom_index"] <- 5 MO_lookup[which(is.na(MO_lookup$kingdom_index)), "kingdom_index"] <- 5
# use this paste instead of `fullname` to work with Viridans Group Streptococci, etc. # use this paste instead of `fullname` to work with Viridans Group Streptococci, etc.
MO_lookup$fullname_lower <- tolower(trimws(paste(MO_lookup$genus, MO_lookup$fullname_lower <- MO_FULLNAME_LOWER
MO_lookup$species,
MO_lookup$subspecies)))
ind <- MO_lookup$genus == "" | grepl("^[(]unknown ", MO_lookup$fullname, perl = TRUE)
MO_lookup[ind, "fullname_lower"] <- tolower(MO_lookup[ind, "fullname"])
MO_lookup$fullname_lower <- trimws(gsub("[^.a-z0-9/ \\-]+", "", MO_lookup$fullname_lower, perl = TRUE))
# add a column with only "e coli" like combinations # add a column with only "e coli" like combinations
MO_lookup$g_species <- gsub("^([a-z])[a-z]+ ([a-z]+) ?.*", "\\1 \\2", MO_lookup$fullname_lower, perl = TRUE) MO_lookup$g_species <- gsub("^([a-z])[a-z]+ ([a-z]+) ?.*", "\\1 \\2", MO_lookup$fullname_lower, perl = TRUE)

View File

@ -1 +1,2 @@
* This package has a data folder size of ~1.7 MB, which might return a NOTE on some R CMD CHECKs. This package size is needed to provide users reference data for the complete taxonomy of microorganisms - one of the most important features of this package, as it has been in the 16 previous releases of this package. All data sets were compressed using `compression = "xz"` to make them as small as possible. Extra release for fixing image options, as requested by CRAN team on 17 February 2022 (Kurt Hornik).

Binary file not shown.

View File

@ -122,9 +122,21 @@ create_species_cons_cops <- function(type = c("CoNS", "CoPS")) {
"mo", drop = TRUE] "mo", drop = TRUE]
} }
} }
create_MO_fullname_lower <- function() {
MO_lookup <- AMR::microorganisms
# use this paste instead of `fullname` to work with Viridans Group Streptococci, etc.
MO_lookup$fullname_lower <- tolower(trimws(paste(MO_lookup$genus,
MO_lookup$species,
MO_lookup$subspecies)))
ind <- MO_lookup$genus == "" | grepl("^[(]unknown ", MO_lookup$fullname, perl = TRUE)
MO_lookup[ind, "fullname_lower"] <- tolower(MO_lookup[ind, "fullname"])
MO_lookup$fullname_lower <- trimws(gsub("[^.a-z0-9/ \\-]+", "", MO_lookup$fullname_lower, perl = TRUE))
MO_lookup$fullname_lower
}
MO_CONS <- create_species_cons_cops("CoNS") MO_CONS <- create_species_cons_cops("CoNS")
MO_COPS <- create_species_cons_cops("CoPS") MO_COPS <- create_species_cons_cops("CoPS")
MO_STREP_ABCG <- as.mo(MO_lookup[which(MO_lookup$genus == "Streptococcus"), "mo", drop = TRUE], Lancefield = TRUE) %in% c("B_STRPT_GRPA", "B_STRPT_GRPB", "B_STRPT_GRPC", "B_STRPT_GRPG") MO_STREP_ABCG <- as.mo(MO_lookup[which(MO_lookup$genus == "Streptococcus"), "mo", drop = TRUE], Lancefield = TRUE) %in% c("B_STRPT_GRPA", "B_STRPT_GRPB", "B_STRPT_GRPC", "B_STRPT_GRPG")
MO_FULLNAME_LOWER <- create_MO_fullname_lower()
# antibiotic groups # antibiotic groups
# (these will also be used for eucast_rules() and understanding data-raw/eucast_rules.tsv) # (these will also be used for eucast_rules() and understanding data-raw/eucast_rules.tsv)
@ -160,6 +172,24 @@ AB_BETALACTAMS <- c(AB_PENICILLINS, AB_CEPHALOSPORINS, AB_CARBAPENEMS)
# this will be used for documentation: # this will be used for documentation:
DEFINED_AB_GROUPS <- ls(envir = globalenv()) DEFINED_AB_GROUPS <- ls(envir = globalenv())
DEFINED_AB_GROUPS <- DEFINED_AB_GROUPS[!DEFINED_AB_GROUPS %in% globalenv_before_ab] DEFINED_AB_GROUPS <- DEFINED_AB_GROUPS[!DEFINED_AB_GROUPS %in% globalenv_before_ab]
create_AB_lookup <- function() {
AB_lookup <- AMR::antibiotics
AB_lookup$generalised_name <- generalise_antibiotic_name(AB_lookup$name)
AB_lookup$generalised_synonyms <- lapply(AB_lookup$synonyms, generalise_antibiotic_name)
AB_lookup$generalised_abbreviations <- lapply(AB_lookup$abbreviations, generalise_antibiotic_name)
AB_lookup$generalised_loinc <- lapply(AB_lookup$loinc, generalise_antibiotic_name)
AB_lookup$generalised_all <- unname(lapply(as.list(as.data.frame(t(AB_lookup[,
c("ab", "atc", "cid", "name",
colnames(AB_lookup)[colnames(AB_lookup) %like% "generalised"]),
drop = FALSE]),
stringsAsFactors = FALSE)),
function(x) {
x <- generalise_antibiotic_name(unname(unlist(x)))
x[x != ""]
}))
AB_lookup[, colnames(AB_lookup)[colnames(AB_lookup) %like% "^generalised"]]
}
AB_LOOKUP <- create_AB_lookup()
# Export to package as internal data ---- # Export to package as internal data ----
usethis::use_data(EUCAST_RULES_DF, usethis::use_data(EUCAST_RULES_DF,
@ -169,6 +199,8 @@ usethis::use_data(EUCAST_RULES_DF,
MO_CONS, MO_CONS,
MO_COPS, MO_COPS,
MO_STREP_ABCG, MO_STREP_ABCG,
MO_FULLNAME_LOWER,
AB_LOOKUP,
AB_AMINOGLYCOSIDES, AB_AMINOGLYCOSIDES,
AB_AMINOPENICILLINS, AB_AMINOPENICILLINS,
AB_ANTIFUNGALS, AB_ANTIFUNGALS,
@ -220,7 +252,9 @@ changed_md5 <- function(object) {
} }
# give official names to ABs and MOs # give official names to ABs and MOs
rsi <- dplyr::mutate(rsi_translation, ab = ab_name(ab), mo = mo_name(mo)) rsi <- AMR::rsi_translation %>%
mutate(mo_name = mo_name(mo, language = NULL), .after = mo) %>%
mutate(ab_name = ab_name(ab, language = NULL), .after = ab)
if (changed_md5(rsi)) { if (changed_md5(rsi)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('rsi_translation')} to {usethis::ui_value('/data-raw/')}")) usethis::ui_info(paste0("Saving {usethis::ui_value('rsi_translation')} to {usethis::ui_value('/data-raw/')}"))
write_md5(rsi) write_md5(rsi)
@ -280,8 +314,8 @@ if (changed_md5(av)) {
} }
# give official names to ABs and MOs # give official names to ABs and MOs
intrinsicR <- data.frame(microorganism = mo_name(intrinsic_resistant$mo), intrinsicR <- data.frame(microorganism = mo_name(intrinsic_resistant$mo, language = NULL),
antibiotic = ab_name(intrinsic_resistant$ab), antibiotic = ab_name(intrinsic_resistant$ab, language = NULL),
stringsAsFactors = FALSE) stringsAsFactors = FALSE)
if (changed_md5(intrinsicR)) { if (changed_md5(intrinsicR)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('intrinsic_resistant')} to {usethis::ui_value('/data-raw/')}")) usethis::ui_info(paste0("Saving {usethis::ui_value('intrinsic_resistant')} to {usethis::ui_value('/data-raw/')}"))

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -26,8 +26,8 @@
# Reproduction of the `microorganisms` data set # Reproduction of the `microorganisms` data set
# Data retrieved from the Catalogue of Life (CoL): # Data retrieved from the Catalogue of Life (CoL):
# https://download.catalogueoflife.org/col/monthly/life/ # https://download.catalogueoflife.org/col/monthly/
# (download latest dwca, such as https://download.catalogueoflife.org/col/monthly/2020-12-01_dwca.zip) # (download latest dwca, such as https://download.catalogueoflife.org/col/monthly/2022-01-14_dwca.zip)
# Data retrieved from the Global Biodiversity Information Facility (GBIF): # Data retrieved from the Global Biodiversity Information Facility (GBIF):
# https://doi.org/10.15468/rffz4x # https://doi.org/10.15468/rffz4x
# #

View File

@ -24,6 +24,7 @@
# ==================================================================== # # ==================================================================== #
# This script runs in under a minute and renews all guidelines of CLSI and EUCAST! # This script runs in under a minute and renews all guidelines of CLSI and EUCAST!
# Run it with source("data-raw/reproduction_of_rsi_translation.R")
library(dplyr) library(dplyr)
library(readr) library(readr)
@ -32,9 +33,9 @@ library(AMR)
# Install the WHONET software on Windows (http://www.whonet.org/software.html), # Install the WHONET software on Windows (http://www.whonet.org/software.html),
# and copy the folder C:\WHONET\Codes to data-raw/WHONET/Codes # and copy the folder C:\WHONET\Codes to data-raw/WHONET/Codes
DRGLST <- readr::read_tsv("data-raw/WHONET/Codes/DRGLST.txt", na = c("", "NA", "-")) DRGLST <- read_tsv("data-raw/WHONET/Codes/DRGLST.txt", na = c("", "NA", "-"), show_col_types = FALSE)
DRGLST1 <- readr::read_tsv("data-raw/WHONET/Codes/DRGLST1.txt", na = c("", "NA", "-")) DRGLST1 <- read_tsv("data-raw/WHONET/Codes/DRGLST1.txt", na = c("", "NA", "-"), show_col_types = FALSE)
ORGLIST <- readr::read_tsv("data-raw/WHONET/Codes/ORGLIST.txt", na = c("", "NA", "-")) ORGLIST <- read_tsv("data-raw/WHONET/Codes/ORGLIST.txt", na = c("", "NA", "-"), show_col_types = FALSE)
# create data set for generic rules (i.e., AB-specific but not MO-specific) # create data set for generic rules (i.e., AB-specific but not MO-specific)
rsi_generic <- DRGLST %>% rsi_generic <- DRGLST %>%
@ -128,11 +129,30 @@ rsi_translation[which(rsi_translation$breakpoint_R == 257), "breakpoint_R"] <- m
rsi_translation[which(rsi_translation$breakpoint_R == 513), "breakpoint_R"] <- m[which(m == 512) + 1] rsi_translation[which(rsi_translation$breakpoint_R == 513), "breakpoint_R"] <- m[which(m == 512) + 1]
rsi_translation[which(rsi_translation$breakpoint_R == 1025), "breakpoint_R"] <- m[which(m == 1024) + 1] rsi_translation[which(rsi_translation$breakpoint_R == 1025), "breakpoint_R"] <- m[which(m == 1024) + 1]
# WHONET adds one log2 level to the R breakpoint for their software, e.g. in AMC in Enterobacterales:
# EUCAST 2021 guideline: S <= 8 and R > 8
# WHONET file: S <= 8 and R >= 16
# this will make an MIC of 12 I, which should be R, so:
eucast_mics <- which(rsi_translation$guideline %like% "EUCAST" &
rsi_translation$method == "MIC" &
log2(as.double(rsi_translation$breakpoint_R)) - log2(as.double(rsi_translation$breakpoint_S)) != 0 &
!is.na(rsi_translation$breakpoint_R))
old_R <- rsi_translation[eucast_mics, "breakpoint_R", drop = TRUE]
old_S <- rsi_translation[eucast_mics, "breakpoint_S", drop = TRUE]
new_R <- 2 ^ (log2(old_R) - 1)
new_R[new_R < old_S | is.na(as.mic(new_R))] <- old_S[new_R < old_S | is.na(as.mic(new_R))]
rsi_translation[eucast_mics, "breakpoint_R"] <- new_R
eucast_disks <- which(rsi_translation$guideline %like% "EUCAST" &
rsi_translation$method == "DISK" &
rsi_translation$breakpoint_S - rsi_translation$breakpoint_R != 0 &
!is.na(rsi_translation$breakpoint_R))
rsi_translation[eucast_disks, "breakpoint_R"] <- rsi_translation[eucast_disks, "breakpoint_R", drop = TRUE] + 1
# Greek symbols and EM dash symbols are not allowed by CRAN, so replace them with ASCII: # Greek symbols and EM dash symbols are not allowed by CRAN, so replace them with ASCII:
rsi_translation$disk_dose <- gsub("μ", "u", rsi_translation$disk_dose, fixed = TRUE) rsi_translation$disk_dose <- gsub("μ", "u", rsi_translation$disk_dose, fixed = TRUE)
rsi_translation$disk_dose <- gsub("", "-", rsi_translation$disk_dose, fixed = TRUE) rsi_translation$disk_dose <- gsub("", "-", rsi_translation$disk_dose, fixed = TRUE)
# save to package # save to package
usethis::use_data(rsi_translation, overwrite = TRUE) usethis::use_data(rsi_translation, overwrite = TRUE, compress = "xz")
rm(rsi_translation) rm(rsi_translation)
devtools::load_all(".") devtools::load_all(".")

View File

@ -1 +1 @@
d8083b68d4e492ea8e87c1eae4da4196 75a10b41a8bd4f4788520f3407431e66

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -43,7 +43,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="https://msberends.github.io/AMR/index.html">AMR (for R)</a> <a class="navbar-link" href="https://msberends.github.io/AMR/index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9010</span>
</span> </span>
</div> </div>
@ -57,7 +57,7 @@
</a> </a>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<a href="https://msberends.github.io/AMR/#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <a href="https://msberends.github.io/AMR/#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span> <span class="fa fa-question-circle"></span>
How to How to
@ -210,7 +210,7 @@ Content not found. Please use links in the navbar.
<div class="pkgdown"> <div class="pkgdown">
<p></p> <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p> <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
</div> </div>
</footer> </footer>

View File

@ -17,7 +17,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9010</span>
</span> </span>
</div> </div>
@ -30,7 +30,7 @@
</a> </a>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span> <span class="fa fa-question-circle"></span>
How to How to
@ -420,7 +420,7 @@ END OF TERMS AND CONDITIONS
</div> </div>
<div class="pkgdown"> <div class="pkgdown">
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p> <p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
</div> </div>
</footer></div> </footer></div>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -44,7 +44,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9008</span>
</span> </span>
</div> </div>
@ -58,7 +58,7 @@
</a> </a>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span> <span class="fa fa-question-circle"></span>
How to How to
@ -201,18 +201,39 @@
<div class="section level2"> <div class="section level2">
<h2 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a> <h2 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
</h2> </h2>
<p>What are EUCAST rules? The European Committee on Antimicrobial Susceptibility Testing (EUCAST) states <a href="https://www.eucast.org/expert_rules_and_intrinsic_resistance/" class="external-link">on their website</a>:</p> <p>What are EUCAST rules? The European Committee on Antimicrobial
Susceptibility Testing (EUCAST) states <a href="https://www.eucast.org/expert_rules_and_intrinsic_resistance/" class="external-link">on
their website</a>:</p>
<blockquote> <blockquote>
<p><em>EUCAST expert rules are a tabulated collection of expert knowledge on intrinsic resistances, exceptional resistance phenotypes and interpretive rules that may be applied to antimicrobial susceptibility testing in order to reduce errors and make appropriate recommendations for reporting particular resistances.</em></p> <p><em>EUCAST expert rules are a tabulated collection of expert
knowledge on intrinsic resistances, exceptional resistance phenotypes
and interpretive rules that may be applied to antimicrobial
susceptibility testing in order to reduce errors and make appropriate
recommendations for reporting particular resistances.</em></p>
</blockquote> </blockquote>
<p>In Europe, a lot of medical microbiological laboratories already apply these rules (<a href="https://www.eurosurveillance.org/content/10.2807/1560-7917.ES2015.20.2.21008" class="external-link">Brown <em>et al.</em>, 2015</a>). Our package features their latest insights on intrinsic resistance and unusual phenotypes (v3.3, 2021).</p> <p>In Europe, a lot of medical microbiological laboratories already
<p>Moreover, the <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> function we use for this purpose can also apply additional rules, like forcing <help title="ATC: J01CA01">ampicillin</help> = R in isolates when <help title="ATC: J01CR02">amoxicillin/clavulanic acid</help> = R.</p> apply these rules (<a href="https://www.eurosurveillance.org/content/10.2807/1560-7917.ES2015.20.2.21008" class="external-link">Brown
<em>et al.</em>, 2015</a>). Our package features their latest insights
on intrinsic resistance and unusual phenotypes (v3.3, 2021).</p>
<p>Moreover, the <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> function we use for this
purpose can also apply additional rules, like forcing
<help title="ATC: J01CA01">ampicillin</help> = R in isolates when
<help title="ATC: J01CR02">amoxicillin/clavulanic acid</help> = R.</p>
</div> </div>
<div class="section level2"> <div class="section level2">
<h2 id="examples">Examples<a class="anchor" aria-label="anchor" href="#examples"></a> <h2 id="examples">Examples<a class="anchor" aria-label="anchor" href="#examples"></a>
</h2> </h2>
<p>These rules can be used to discard impossible bug-drug combinations in your data. For example, <em>Klebsiella</em> produces beta-lactamase that prevents ampicillin (or amoxicillin) from working against it. In other words, practically every strain of <em>Klebsiella</em> is resistant to ampicillin.</p> <p>These rules can be used to discard impossible bug-drug combinations
<p>Sometimes, laboratory data can still contain such strains with ampicillin being susceptible to ampicillin. This could be because an antibiogram is available before an identification is available, and the antibiogram is then not re-interpreted based on the identification (namely, <em>Klebsiella</em>). EUCAST expert rules solve this, that can be applied using <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code>:</p> in your data. For example, <em>Klebsiella</em> produces beta-lactamase
that prevents ampicillin (or amoxicillin) from working against it. In
other words, practically every strain of <em>Klebsiella</em> is
resistant to ampicillin.</p>
<p>Sometimes, laboratory data can still contain such strains with
ampicillin being susceptible to ampicillin. This could be because an
antibiogram is available before an identification is available, and the
antibiogram is then not re-interpreted based on the identification
(namely, <em>Klebsiella</em>). EUCAST expert rules solve this, that can
be applied using <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code>:</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">oops</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>mo <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Klebsiella"</span>, <code class="sourceCode R"><span class="va">oops</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>mo <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Klebsiella"</span>,
<span class="st">"Escherichia"</span><span class="op">)</span>, <span class="st">"Escherichia"</span><span class="op">)</span>,
@ -226,7 +247,10 @@
<span class="co"># mo ampicillin</span> <span class="co"># mo ampicillin</span>
<span class="co"># 1 Klebsiella R</span> <span class="co"># 1 Klebsiella R</span>
<span class="co"># 2 Escherichia S</span></code></pre></div> <span class="co"># 2 Escherichia S</span></code></pre></div>
<p>A more convenient function is <code><a href="../reference/mo_property.html">mo_is_intrinsic_resistant()</a></code> that uses the same guideline, but allows to check for one or more specific microorganisms or antibiotics:</p> <p>A more convenient function is
<code><a href="../reference/mo_property.html">mo_is_intrinsic_resistant()</a></code> that uses the same guideline,
but allows to check for one or more specific microorganisms or
antibiotics:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/mo_property.html">mo_is_intrinsic_resistant</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Klebsiella"</span>, <span class="st">"Escherichia"</span><span class="op">)</span>, <code class="sourceCode R"><span class="fu"><a href="../reference/mo_property.html">mo_is_intrinsic_resistant</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Klebsiella"</span>, <span class="st">"Escherichia"</span><span class="op">)</span>,
<span class="st">"ampicillin"</span><span class="op">)</span> <span class="st">"ampicillin"</span><span class="op">)</span>
@ -235,7 +259,11 @@
<span class="fu"><a href="../reference/mo_property.html">mo_is_intrinsic_resistant</a></span><span class="op">(</span><span class="st">"Klebsiella"</span>, <span class="fu"><a href="../reference/mo_property.html">mo_is_intrinsic_resistant</a></span><span class="op">(</span><span class="st">"Klebsiella"</span>,
<span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"ampicillin"</span>, <span class="st">"kanamycin"</span><span class="op">)</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"ampicillin"</span>, <span class="st">"kanamycin"</span><span class="op">)</span><span class="op">)</span>
<span class="co"># [1] TRUE FALSE</span></code></pre></div> <span class="co"># [1] TRUE FALSE</span></code></pre></div>
<p>EUCAST rules can not only be used for correction, they can also be used for filling in known resistance and susceptibility based on results of other antimicrobials drugs. This process is called <em>interpretive reading</em>, is basically a form of imputation, and is part of the <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> function as well:</p> <p>EUCAST rules can not only be used for correction, they can also be
used for filling in known resistance and susceptibility based on results
of other antimicrobials drugs. This process is called <em>interpretive
reading</em>, is basically a form of imputation, and is part of the
<code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> function as well:</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>mo <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Staphylococcus aureus"</span>, <code class="sourceCode R"><span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>mo <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Staphylococcus aureus"</span>,
<span class="st">"Enterococcus faecalis"</span>, <span class="st">"Enterococcus faecalis"</span>,
@ -402,7 +430,7 @@
<div class="pkgdown"> <div class="pkgdown">
<p></p> <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p> <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
</div> </div>
</footer> </footer>

View File

@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -44,7 +44,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9008</span>
</span> </span>
</div> </div>
@ -58,7 +58,7 @@
</a> </a>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span> <span class="fa fa-question-circle"></span>
How to How to
@ -188,7 +188,8 @@
</header><div class="row"> </header><div class="row">
<div class="col-md-9 contents"> <div class="col-md-9 contents">
<div class="page-header toc-ignore"> <div class="page-header toc-ignore">
<h1 data-toc-skip>How to determine multi-drug resistance (MDR)</h1> <h1 data-toc-skip>How to determine multi-drug resistance
(MDR)</h1>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/MDR.Rmd" class="external-link"><code>vignettes/MDR.Rmd</code></a></small> <small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/MDR.Rmd" class="external-link"><code>vignettes/MDR.Rmd</code></a></small>
@ -198,54 +199,87 @@
<p>With the function <code><a href="../reference/mdro.html">mdro()</a></code>, you can determine which micro-organisms are multi-drug resistant organisms (MDRO).</p> <p>With the function <code><a href="../reference/mdro.html">mdro()</a></code>, you can determine which
micro-organisms are multi-drug resistant organisms (MDRO).</p>
<div class="section level3"> <div class="section level3">
<h3 id="type-of-input">Type of input<a class="anchor" aria-label="anchor" href="#type-of-input"></a> <h3 id="type-of-input">Type of input<a class="anchor" aria-label="anchor" href="#type-of-input"></a>
</h3> </h3>
<p>The <code><a href="../reference/mdro.html">mdro()</a></code> function takes a data set as input, such as a regular <code>data.frame</code>. It tries to automatically determine the right columns for info about your isolates, such as the name of the species and all columns with results of antimicrobial agents. See the help page for more info about how to set the right settings for your data with the command <code><a href="../reference/mdro.html">?mdro</a></code>.</p> <p>The <code><a href="../reference/mdro.html">mdro()</a></code> function takes a data set as input, such as a
<p>For WHONET data (and most other data), all settings are automatically set correctly.</p> regular <code>data.frame</code>. It tries to automatically determine the
right columns for info about your isolates, such as the name of the
species and all columns with results of antimicrobial agents. See the
help page for more info about how to set the right settings for your
data with the command <code><a href="../reference/mdro.html">?mdro</a></code>.</p>
<p>For WHONET data (and most other data), all settings are automatically
set correctly.</p>
</div> </div>
<div class="section level3"> <div class="section level3">
<h3 id="guidelines">Guidelines<a class="anchor" aria-label="anchor" href="#guidelines"></a> <h3 id="guidelines">Guidelines<a class="anchor" aria-label="anchor" href="#guidelines"></a>
</h3> </h3>
<p>The <code><a href="../reference/mdro.html">mdro()</a></code> function support multiple guidelines. You can select a guideline with the <code>guideline</code> parameter. Currently supported guidelines are (case-insensitive):</p> <p>The <code><a href="../reference/mdro.html">mdro()</a></code> function support multiple guidelines. You can
select a guideline with the <code>guideline</code> parameter. Currently
supported guidelines are (case-insensitive):</p>
<ul> <ul>
<li> <li>
<p><code>guideline = "CMI2012"</code> (default)</p> <p><code>guideline = "CMI2012"</code> (default)</p>
<p>Magiorakos AP, Srinivasan A <em>et al.</em> “Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance.” Clinical Microbiology and Infection (2012) (<a href="https://www.clinicalmicrobiologyandinfection.com/article/S1198-743X(14)61632-3/fulltext" class="external-link">link</a>)</p> <p>Magiorakos AP, Srinivasan A <em>et al.</em> “Multidrug-resistant,
extensively drug-resistant and pandrug-resistant bacteria: an
international expert proposal for interim standard definitions for
acquired resistance.” Clinical Microbiology and Infection (2012) (<a href="https://www.clinicalmicrobiologyandinfection.com/article/S1198-743X(14)61632-3/fulltext" class="external-link">link</a>)</p>
</li> </li>
<li> <li>
<p><code>guideline = "EUCAST3.2"</code> (or simply <code>guideline = "EUCAST"</code>)</p> <p><code>guideline = "EUCAST3.2"</code> (or simply
<p>The European international guideline - EUCAST Expert Rules Version 3.2 “Intrinsic Resistance and Unusual Phenotypes” (<a href="https://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/2020/Intrinsic_Resistance_and_Unusual_Phenotypes_Tables_v3.2_20200225.pdf" class="external-link">link</a>)</p> <code>guideline = "EUCAST"</code>)</p>
<p>The European international guideline - EUCAST Expert Rules Version
3.2 “Intrinsic Resistance and Unusual Phenotypes” (<a href="https://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/2020/Intrinsic_Resistance_and_Unusual_Phenotypes_Tables_v3.2_20200225.pdf" class="external-link">link</a>)</p>
</li> </li>
<li> <li>
<p><code>guideline = "EUCAST3.1"</code></p> <p><code>guideline = "EUCAST3.1"</code></p>
<p>The European international guideline - EUCAST Expert Rules Version 3.1 “Intrinsic Resistance and Exceptional Phenotypes Tables” (<a href="https://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf" class="external-link">link</a>)</p> <p>The European international guideline - EUCAST Expert Rules Version
3.1 “Intrinsic Resistance and Exceptional Phenotypes Tables” (<a href="https://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf" class="external-link">link</a>)</p>
</li> </li>
<li> <li>
<p><code>guideline = "TB"</code></p> <p><code>guideline = "TB"</code></p>
<p>The international guideline for multi-drug resistant tuberculosis - World Health Organization “Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis” (<a href="https://www.who.int/tb/publications/pmdt_companionhandbook/en/" class="external-link">link</a>)</p> <p>The international guideline for multi-drug resistant tuberculosis -
World Health Organization “Companion handbook to the WHO guidelines for
the programmatic management of drug-resistant tuberculosis” (<a href="https://www.who.int/tb/publications/pmdt_companionhandbook/en/" class="external-link">link</a>)</p>
</li> </li>
<li> <li>
<p><code>guideline = "MRGN"</code></p> <p><code>guideline = "MRGN"</code></p>
<p>The German national guideline - Mueller <em>et al.</em> (2015) Antimicrobial Resistance and Infection Control 4:7. DOI: 10.1186/s13756-015-0047-6</p> <p>The German national guideline - Mueller <em>et al.</em> (2015)
Antimicrobial Resistance and Infection Control 4:7. DOI:
10.1186/s13756-015-0047-6</p>
</li> </li>
<li> <li>
<p><code>guideline = "BRMO"</code></p> <p><code>guideline = "BRMO"</code></p>
<p>The Dutch national guideline - Rijksinstituut voor Volksgezondheid en Milieu “WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) (ZKH)” (<a href="https://www.rivm.nl/wip-richtlijn-brmo-bijzonder-resistente-micro-organismen-zkh" class="external-link">link</a>)</p> <p>The Dutch national guideline - Rijksinstituut voor Volksgezondheid en
Milieu “WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen)
(ZKH)” (<a href="https://www.rivm.nl/wip-richtlijn-brmo-bijzonder-resistente-micro-organismen-zkh" class="external-link">link</a>)</p>
</li> </li>
</ul> </ul>
<p>Please suggest your own (country-specific) guidelines by letting us know: <a href="https://github.com/msberends/AMR/issues/new" class="external-link uri">https://github.com/msberends/AMR/issues/new</a>.</p> <p>Please suggest your own (country-specific) guidelines by letting us
know: <a href="https://github.com/msberends/AMR/issues/new" class="external-link uri">https://github.com/msberends/AMR/issues/new</a>.</p>
<div class="section level4"> <div class="section level4">
<h4 id="custom-guidelines">Custom Guidelines<a class="anchor" aria-label="anchor" href="#custom-guidelines"></a> <h4 id="custom-guidelines">Custom Guidelines<a class="anchor" aria-label="anchor" href="#custom-guidelines"></a>
</h4> </h4>
<p>You can also use your own custom guideline. Custom guidelines can be set with the <code><a href="../reference/mdro.html">custom_mdro_guideline()</a></code> function. This is of great importance if you have custom rules to determine MDROs in your hospital, e.g., rules that are dependent on ward, state of contact isolation or other variables in your data.</p> <p>You can also use your own custom guideline. Custom guidelines can be
<p>If you are familiar with <code><a href="https://dplyr.tidyverse.org/reference/case_when.html" class="external-link">case_when()</a></code> of the <code>dplyr</code> package, you will recognise the input method to set your own rules. Rules must be set using what R considers to be the formula notation:</p> set with the <code><a href="../reference/mdro.html">custom_mdro_guideline()</a></code> function. This is of
great importance if you have custom rules to determine MDROs in your
hospital, e.g., rules that are dependent on ward, state of contact
isolation or other variables in your data.</p>
<p>If you are familiar with <code><a href="https://dplyr.tidyverse.org/reference/case_when.html" class="external-link">case_when()</a></code> of the
<code>dplyr</code> package, you will recognise the input method to set
your own rules. Rules must be set using what R considers to be the
formula notation:</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">custom</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/mdro.html">custom_mdro_guideline</a></span><span class="op">(</span><span class="va">CIP</span> <span class="op">==</span> <span class="st">"R"</span> <span class="op">&amp;</span> <span class="va">age</span> <span class="op">&gt;</span> <span class="fl">60</span> <span class="op">~</span> <span class="st">"Elderly Type A"</span>, <code class="sourceCode R"><span class="va">custom</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/mdro.html">custom_mdro_guideline</a></span><span class="op">(</span><span class="va">CIP</span> <span class="op">==</span> <span class="st">"R"</span> <span class="op">&amp;</span> <span class="va">age</span> <span class="op">&gt;</span> <span class="fl">60</span> <span class="op">~</span> <span class="st">"Elderly Type A"</span>,
<span class="va">ERY</span> <span class="op">==</span> <span class="st">"R"</span> <span class="op">&amp;</span> <span class="va">age</span> <span class="op">&gt;</span> <span class="fl">60</span> <span class="op">~</span> <span class="st">"Elderly Type B"</span><span class="op">)</span></code></pre></div> <span class="va">ERY</span> <span class="op">==</span> <span class="st">"R"</span> <span class="op">&amp;</span> <span class="va">age</span> <span class="op">&gt;</span> <span class="fl">60</span> <span class="op">~</span> <span class="st">"Elderly Type B"</span><span class="op">)</span></code></pre></div>
<p>If a row/an isolate matches the first rule, the value after the first <code>~</code> (in this case <em>Elderly Type A</em>) will be set as MDRO value. Otherwise, the second rule will be tried and so on. The maximum number of rules is unlimited.</p> <p>If a row/an isolate matches the first rule, the value after the first
<p>You can print the rules set in the console for an overview. Colours will help reading it if your console supports colours.</p> <code>~</code> (in this case <em>Elderly Type A</em>) will be set as
MDRO value. Otherwise, the second rule will be tried and so on. The
maximum number of rules is unlimited.</p>
<p>You can print the rules set in the console for an overview. Colours
will help reading it if your console supports colours.</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">custom</span> <code class="sourceCode R"><span class="va">custom</span>
<span class="co"># A set of custom MDRO rules:</span> <span class="co"># A set of custom MDRO rules:</span>
@ -255,7 +289,8 @@
<span class="co"># </span> <span class="co"># </span>
<span class="co"># Unmatched rows will return NA.</span> <span class="co"># Unmatched rows will return NA.</span>
<span class="co"># Results will be of class &lt;factor&gt;, with ordered levels: Negative &lt; Elderly Type A &lt; Elderly Type B</span></code></pre></div> <span class="co"># Results will be of class &lt;factor&gt;, with ordered levels: Negative &lt; Elderly Type A &lt; Elderly Type B</span></code></pre></div>
<p>The outcome of the function can be used for the <code>guideline</code> argument in the <code><a href="../reference/mdro.html">mdro()</a></code> function:</p> <p>The outcome of the function can be used for the
<code>guideline</code> argument in the <code><a href="../reference/mdro.html">mdro()</a></code> function:</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/mdro.html">mdro</a></span><span class="op">(</span><span class="va">example_isolates</span>, guideline <span class="op">=</span> <span class="va">custom</span><span class="op">)</span> <code class="sourceCode R"><span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/mdro.html">mdro</a></span><span class="op">(</span><span class="va">example_isolates</span>, guideline <span class="op">=</span> <span class="va">custom</span><span class="op">)</span>
<span class="co"># Determining MDROs based on custom rules, resulting in factor levels:</span> <span class="co"># Determining MDROs based on custom rules, resulting in factor levels:</span>
@ -266,14 +301,25 @@
<span class="co"># x</span> <span class="co"># x</span>
<span class="co"># Negative Elderly Type A Elderly Type B </span> <span class="co"># Negative Elderly Type A Elderly Type B </span>
<span class="co"># 1070 198 732</span></code></pre></div> <span class="co"># 1070 198 732</span></code></pre></div>
<p>The rules set (the <code>custom</code> object in this case) could be exported to a shared file location using <code><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">saveRDS()</a></code> if you collaborate with multiple users. The custom rules set could then be imported using <code><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">readRDS()</a></code>.</p> <p>The rules set (the <code>custom</code> object in this case) could be
exported to a shared file location using <code><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">saveRDS()</a></code> if you
collaborate with multiple users. The custom rules set could then be
imported using <code><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">readRDS()</a></code>.</p>
</div> </div>
</div> </div>
<div class="section level3"> <div class="section level3">
<h3 id="examples">Examples<a class="anchor" aria-label="anchor" href="#examples"></a> <h3 id="examples">Examples<a class="anchor" aria-label="anchor" href="#examples"></a>
</h3> </h3>
<p>The <code><a href="../reference/mdro.html">mdro()</a></code> function always returns an ordered <code>factor</code> for predefined guidelines. For example, the output of the default guideline by Magiorakos <em>et al.</em> returns a <code>factor</code> with levels Negative, MDR, XDR or PDR in that order.</p> <p>The <code><a href="../reference/mdro.html">mdro()</a></code> function always returns an ordered
<p>The next example uses the <code>example_isolates</code> data set. This is a data set included with this package and contains full antibiograms of 2,000 microbial isolates. It reflects reality and can be used to practise AMR data analysis. If we test the MDR/XDR/PDR guideline on this data set, we get:</p> <code>factor</code> for predefined guidelines. For example, the output
of the default guideline by Magiorakos <em>et al.</em> returns a
<code>factor</code> with levels Negative, MDR, XDR or PDR in
that order.</p>
<p>The next example uses the <code>example_isolates</code> data set.
This is a data set included with this package and contains full
antibiograms of 2,000 microbial isolates. It reflects reality and can be
used to practise AMR data analysis. If we test the MDR/XDR/PDR guideline
on this data set, we get:</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span> <span class="co"># to support pipes: %&gt;%</span> <code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span> <span class="co"># to support pipes: %&gt;%</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/msberends/cleaner" class="external-link">cleaner</a></span><span class="op">)</span> <span class="co"># to create frequency tables</span></code></pre></div> <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/msberends/cleaner" class="external-link">cleaner</a></span><span class="op">)</span> <span class="co"># to create frequency tables</span></code></pre></div>
@ -295,18 +341,34 @@
<span class="co"># Table 3 - Enterobacteriaceae... OK.</span> <span class="co"># Table 3 - Enterobacteriaceae... OK.</span>
<span class="co"># Table 4 - Pseudomonas aeruginosa... OK.</span> <span class="co"># Table 4 - Pseudomonas aeruginosa... OK.</span>
<span class="co"># Table 5 - Acinetobacter spp.... OK.</span> <span class="co"># Table 5 - Acinetobacter spp.... OK.</span>
<span class="co"># Warning: NA introduced for isolates where the available percentage of antimicrobial</span> <span class="co"># Warning: in `mdro()`: NA introduced for isolates where the available percentage of</span>
<span class="co"># classes was below 50% (set with `pct_required_classes`)</span></code></pre></div> <span class="co"># antimicrobial classes was below 50% (set with `pct_required_classes`)</span></code></pre></div>
<p>Only results with R are considered as resistance. Use <code>combine_SI = FALSE</code> to also consider I as resistance.</p> <p>Only results with R are considered as resistance. Use
<p>Determining multidrug-resistant organisms (MDRO), according to: Guideline: Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance. Author(s): Magiorakos AP, Srinivasan A, Carey RB, …, Vatopoulos A, Weber JT, Monnet DL Source: Clinical Microbiology and Infection 18:3, 2012; doi: 10.1111/j.1469-0691.2011.03570.x</p> <code>combine_SI = FALSE</code> to also consider I as resistance.</p>
<p>Determining multidrug-resistant organisms (MDRO), according to:
Guideline: Multidrug-resistant, extensively drug-resistant and
pandrug-resistant bacteria: an international expert proposal for interim
standard definitions for acquired resistance. Author(s): Magiorakos AP,
Srinivasan A, Carey RB, …, Vatopoulos A, Weber JT, Monnet DL Source:
Clinical Microbiology and Infection 18:3, 2012; doi:
10.1111/j.1469-0691.2011.03570.x</p>
<p>(16 isolates had no test results)</p> <p>(16 isolates had no test results)</p>
<p><strong>Frequency table</strong></p> <p><strong>Frequency table</strong></p>
<p>Class: factor &gt; ordered (numeric)<br> <p>Class: factor &gt; ordered (numeric)<br>
Length: 2,000<br> Length: 2,000<br>
Levels: 4: Negative &lt; Multi-drug-resistant (MDR) &lt; Extensively drug-resistant …<br> Levels: 4: Negative &lt; Multi-drug-resistant (MDR) &lt; Extensively
drug-resistant …<br>
Available: 1,729 (86.45%, NA: 271 = 13.55%)<br> Available: 1,729 (86.45%, NA: 271 = 13.55%)<br>
Unique: 2</p> Unique: 2</p>
<table class="table"> <table style="width:100%;" class="table">
<colgroup>
<col width="4%">
<col width="38%">
<col width="9%">
<col width="12%">
<col width="16%">
<col width="19%">
</colgroup>
<thead><tr class="header"> <thead><tr class="header">
<th align="left"></th> <th align="left"></th>
<th align="left">Item</th> <th align="left">Item</th>
@ -320,21 +382,22 @@ Unique: 2</p>
<td align="left">1</td> <td align="left">1</td>
<td align="left">Negative</td> <td align="left">Negative</td>
<td align="right">1601</td> <td align="right">1601</td>
<td align="right">92.60%</td> <td align="right">92.6%</td>
<td align="right">1601</td> <td align="right">1601</td>
<td align="right">92.60%</td> <td align="right">92.6%</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td align="left">2</td> <td align="left">2</td>
<td align="left">Multi-drug-resistant (MDR)</td> <td align="left">Multi-drug-resistant (MDR)</td>
<td align="right">128</td> <td align="right">128</td>
<td align="right">7.40%</td> <td align="right">7.4%</td>
<td align="right">1729</td> <td align="right">1729</td>
<td align="right">100.00%</td> <td align="right">100.0%</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<p>For another example, I will create a data set to determine multi-drug resistant TB:</p> <p>For another example, I will create a data set to determine multi-drug
resistant TB:</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># random_rsi() is a helper function to generate</span> <code class="sourceCode R"><span class="co"># random_rsi() is a helper function to generate</span>
<span class="co"># a random vector with values S, I and R</span> <span class="co"># a random vector with values S, I and R</span>
@ -345,7 +408,8 @@ Unique: 2</p>
pyrazinamide <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>, pyrazinamide <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,
moxifloxacin <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>, moxifloxacin <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,
kanamycin <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span><span class="op">)</span></code></pre></div> kanamycin <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span><span class="op">)</span></code></pre></div>
<p>Because all column names are automatically verified for valid drug names or codes, this would have worked exactly the same way:</p> <p>Because all column names are automatically verified for valid drug
names or codes, this would have worked exactly the same way:</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">my_TB_data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>RIF <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>, <code class="sourceCode R"><span class="va">my_TB_data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>RIF <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,
INH <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>, INH <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_rsi</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,
@ -358,20 +422,21 @@ Unique: 2</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">my_TB_data</span><span class="op">)</span> <code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">my_TB_data</span><span class="op">)</span>
<span class="co"># rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin</span> <span class="co"># rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin</span>
<span class="co"># 1 I R I S R S</span> <span class="co"># 1 R I R R I S</span>
<span class="co"># 2 I S R R S R</span> <span class="co"># 2 I I S S R S</span>
<span class="co"># 3 R I S I R S</span> <span class="co"># 3 I S R R S R</span>
<span class="co"># 4 S S I R I S</span> <span class="co"># 4 R I S R R I</span>
<span class="co"># 5 S R S S S I</span> <span class="co"># 5 R I I I R I</span>
<span class="co"># 6 S R R S R I</span> <span class="co"># 6 R I R S R I</span>
<span class="co"># kanamycin</span> <span class="co"># kanamycin</span>
<span class="co"># 1 S</span> <span class="co"># 1 R</span>
<span class="co"># 2 I</span> <span class="co"># 2 R</span>
<span class="co"># 3 R</span> <span class="co"># 3 S</span>
<span class="co"># 4 R</span> <span class="co"># 4 I</span>
<span class="co"># 5 I</span> <span class="co"># 5 I</span>
<span class="co"># 6 R</span></code></pre></div> <span class="co"># 6 R</span></code></pre></div>
<p>We can now add the interpretation of MDR-TB to our data set. You can use:</p> <p>We can now add the interpretation of MDR-TB to our data set. You can
use:</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/mdro.html">mdro</a></span><span class="op">(</span><span class="va">my_TB_data</span>, guideline <span class="op">=</span> <span class="st">"TB"</span><span class="op">)</span></code></pre></div> <code class="sourceCode R"><span class="fu"><a href="../reference/mdro.html">mdro</a></span><span class="op">(</span><span class="va">my_TB_data</span>, guideline <span class="op">=</span> <span class="st">"TB"</span><span class="op">)</span></code></pre></div>
<p>or its shortcut <code><a href="../reference/mdro.html">mdr_tb()</a></code>:</p> <p>or its shortcut <code><a href="../reference/mdro.html">mdr_tb()</a></code>:</p>
@ -390,17 +455,26 @@ Unique: 2</p>
<span class="co"># management of drug-resistant tuberculosis</span> <span class="co"># management of drug-resistant tuberculosis</span>
<span class="co"># Author(s): WHO (World Health Organization)</span> <span class="co"># Author(s): WHO (World Health Organization)</span>
<span class="co"># Version: WHO/HTM/TB/2014.11, 2014</span> <span class="co"># Version: WHO/HTM/TB/2014.11, 2014</span>
<span class="co"># Source: https://www.who.int/tb/publications/pmdt_companionhandbook/en/</span></code></pre></div> <span class="co"># Source: https://www.who.int/publications/i/item/9789241548809</span></code></pre></div>
<p>Create a frequency table of the results:</p> <p>Create a frequency table of the results:</p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html" class="external-link">freq</a></span><span class="op">(</span><span class="va">my_TB_data</span><span class="op">$</span><span class="va">mdr</span><span class="op">)</span></code></pre></div> <code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html" class="external-link">freq</a></span><span class="op">(</span><span class="va">my_TB_data</span><span class="op">$</span><span class="va">mdr</span><span class="op">)</span></code></pre></div>
<p><strong>Frequency table</strong></p> <p><strong>Frequency table</strong></p>
<p>Class: factor &gt; ordered (numeric)<br> <p>Class: factor &gt; ordered (numeric)<br>
Length: 5,000<br> Length: 5,000<br>
Levels: 5: Negative &lt; Mono-resistant &lt; Poly-resistant &lt; Multi-drug-resistant &lt;<br> Levels: 5: Negative &lt; Mono-resistant &lt; Poly-resistant &lt;
Available: 5,000 (100.0%, NA: 0 = 0.0%)<br> Multi-drug-resistant &lt;<br>
Available: 5,000 (100%, NA: 0 = 0%)<br>
Unique: 5</p> Unique: 5</p>
<table class="table"> <table style="width:100%;" class="table">
<colgroup>
<col width="4%">
<col width="38%">
<col width="9%">
<col width="12%">
<col width="16%">
<col width="19%">
</colgroup>
<thead><tr class="header"> <thead><tr class="header">
<th align="left"></th> <th align="left"></th>
<th align="left">Item</th> <th align="left">Item</th>
@ -413,40 +487,40 @@ Unique: 5</p>
<tr class="odd"> <tr class="odd">
<td align="left">1</td> <td align="left">1</td>
<td align="left">Mono-resistant</td> <td align="left">Mono-resistant</td>
<td align="right">3250</td> <td align="right">3218</td>
<td align="right">65.00%</td> <td align="right">64.36%</td>
<td align="right">3250</td> <td align="right">3218</td>
<td align="right">65.00%</td> <td align="right">64.36%</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td align="left">2</td> <td align="left">2</td>
<td align="left">Negative</td> <td align="left">Negative</td>
<td align="right">975</td> <td align="right">979</td>
<td align="right">19.50%</td> <td align="right">19.58%</td>
<td align="right">4225</td> <td align="right">4197</td>
<td align="right">84.50%</td> <td align="right">83.94%</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td align="left">3</td> <td align="left">3</td>
<td align="left">Multi-drug-resistant</td> <td align="left">Multi-drug-resistant</td>
<td align="right">474</td> <td align="right">458</td>
<td align="right">9.48%</td> <td align="right">9.16%</td>
<td align="right">4699</td> <td align="right">4655</td>
<td align="right">93.98%</td> <td align="right">93.10%</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td align="left">4</td> <td align="left">4</td>
<td align="left">Poly-resistant</td> <td align="left">Poly-resistant</td>
<td align="right">203</td> <td align="right">237</td>
<td align="right">4.06%</td> <td align="right">4.74%</td>
<td align="right">4902</td> <td align="right">4892</td>
<td align="right">98.04%</td> <td align="right">97.84%</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td align="left">5</td> <td align="left">5</td>
<td align="left">Extensively drug-resistant</td> <td align="left">Extensively drug-resistant</td>
<td align="right">98</td> <td align="right">108</td>
<td align="right">1.96%</td> <td align="right">2.16%</td>
<td align="right">5000</td> <td align="right">5000</td>
<td align="right">100.00%</td> <td align="right">100.00%</td>
</tr> </tr>
@ -470,7 +544,7 @@ Unique: 5</p>
<div class="pkgdown"> <div class="pkgdown">
<p></p> <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p> <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
</div> </div>
</footer> </footer>

View File

@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -44,7 +44,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9008</span>
</span> </span>
</div> </div>
@ -58,7 +58,7 @@
</a> </a>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span> <span class="fa fa-question-circle"></span>
How to How to
@ -188,7 +188,8 @@
</header><div class="row"> </header><div class="row">
<div class="col-md-9 contents"> <div class="col-md-9 contents">
<div class="page-header toc-ignore"> <div class="page-header toc-ignore">
<h1 data-toc-skip>How to conduct principal component analysis (PCA) for AMR</h1> <h1 data-toc-skip>How to conduct principal component analysis
(PCA) for AMR</h1>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/PCA.Rmd" class="external-link"><code>vignettes/PCA.Rmd</code></a></small> <small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/PCA.Rmd" class="external-link"><code>vignettes/PCA.Rmd</code></a></small>
@ -198,19 +199,21 @@
<p><strong>NOTE: This page will be updated soon, as the pca() function is currently being developed.</strong></p> <p><strong>NOTE: This page will be updated soon, as the pca() function
<div class="section level1"> is currently being developed.</strong></p>
<h1 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a> <div class="section level2">
</h1> <h2 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
</h2>
</div> </div>
<div class="section level1"> <div class="section level2">
<h1 id="transforming">Transforming<a class="anchor" aria-label="anchor" href="#transforming"></a> <h2 id="transforming">Transforming<a class="anchor" aria-label="anchor" href="#transforming"></a>
</h1> </h2>
<p>For PCA, we need to transform our AMR data first. This is what the <code>example_isolates</code> data set in this package looks like:</p> <p>For PCA, we need to transform our AMR data first. This is what the
<code>example_isolates</code> data set in this package looks like:</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR">AMR</a></span><span class="op">)</span> <code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR/">AMR</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span> <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span>
<span class="fu"><a href="https://pillar.r-lib.org/reference/glimpse.html" class="external-link">glimpse</a></span><span class="op">(</span><span class="va">example_isolates</span><span class="op">)</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/glimpse.html" class="external-link">glimpse</a></span><span class="op">(</span><span class="va">example_isolates</span><span class="op">)</span>
<span class="co"># Rows: 2,000</span> <span class="co"># Rows: 2,000</span>
<span class="co"># Columns: 49</span> <span class="co"># Columns: 49</span>
<span class="co"># $ date <span style="color: #949494; font-style: italic;">&lt;date&gt;</span> 2002-01-02, 2002-01-03, 2002-01-07, 2002-01-07, 2002-…</span> <span class="co"># $ date <span style="color: #949494; font-style: italic;">&lt;date&gt;</span> 2002-01-02, 2002-01-03, 2002-01-07, 2002-01-07, 2002-…</span>
@ -262,7 +265,8 @@
<span class="co"># $ COL <span style="color: #949494; font-style: italic;">&lt;rsi&gt;</span> NA, NA, R, R, R, R, R, R, R, R, R, R, NA, NA, NA, R, R…</span> <span class="co"># $ COL <span style="color: #949494; font-style: italic;">&lt;rsi&gt;</span> NA, NA, R, R, R, R, R, R, R, R, R, R, NA, NA, NA, R, R…</span>
<span class="co"># $ MUP <span style="color: #949494; font-style: italic;">&lt;rsi&gt;</span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span> <span class="co"># $ MUP <span style="color: #949494; font-style: italic;">&lt;rsi&gt;</span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span>
<span class="co"># $ RIF <span style="color: #949494; font-style: italic;">&lt;rsi&gt;</span> R, R, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, R, R,…</span></code></pre></div> <span class="co"># $ RIF <span style="color: #949494; font-style: italic;">&lt;rsi&gt;</span> R, R, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, R, R,…</span></code></pre></div>
<p>Now to transform this to a data set with only resistance percentages per taxonomic order and genus:</p> <p>Now to transform this to a data set with only resistance percentages
per taxonomic order and genus:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">resistance_data</span> <span class="op">&lt;-</span> <span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <code class="sourceCode R"><span class="va">resistance_data</span> <span class="op">&lt;-</span> <span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span>order <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_order</a></span><span class="op">(</span><span class="va">mo</span><span class="op">)</span>, <span class="co"># group on anything, like order</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span>order <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_order</a></span><span class="op">(</span><span class="va">mo</span><span class="op">)</span>, <span class="co"># group on anything, like order</span>
@ -283,35 +287,44 @@
<span class="co"># <span style="color: #BCBCBC;">5</span> Caryophanales Gemella <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span> <span class="co"># <span style="color: #BCBCBC;">5</span> Caryophanales Gemella <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span>
<span class="co"># <span style="color: #BCBCBC;">6</span> Caryophanales Listeria <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span></code></pre></div> <span class="co"># <span style="color: #BCBCBC;">6</span> Caryophanales Listeria <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span></code></pre></div>
</div> </div>
<div class="section level1"> <div class="section level2">
<h1 id="perform-principal-component-analysis">Perform principal component analysis<a class="anchor" aria-label="anchor" href="#perform-principal-component-analysis"></a> <h2 id="perform-principal-component-analysis">Perform principal component analysis<a class="anchor" aria-label="anchor" href="#perform-principal-component-analysis"></a>
</h1> </h2>
<p>The new <code><a href="../reference/pca.html">pca()</a></code> function will automatically filter on rows that contain numeric values in all selected variables, so we now only need to do:</p> <p>The new <code><a href="../reference/pca.html">pca()</a></code> function will automatically filter on rows
that contain numeric values in all selected variables, so we now only
need to do:</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">pca_result</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/pca.html">pca</a></span><span class="op">(</span><span class="va">resistance_data</span><span class="op">)</span> <code class="sourceCode R"><span class="va">pca_result</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/pca.html">pca</a></span><span class="op">(</span><span class="va">resistance_data</span><span class="op">)</span>
<span class="co"># Columns selected for PCA: "AMC", "CAZ", "CTX", "CXM", "GEN", "SXT", "TMP"</span> <span class="co"># Columns selected for PCA: "AMC", "CAZ", "CTX", "CXM", "GEN", "SXT", "TMP"</span>
<span class="co"># and "TOB". Total observations available: 7.</span></code></pre></div> <span class="co"># and "TOB". Total observations available: 7.</span></code></pre></div>
<p>The result can be reviewed with the good old <code><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary()</a></code> function:</p> <p>The result can be reviewed with the good old <code><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary()</a></code>
function:</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span> <code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span>
<span class="co"># Groups (n=4, named as 'order'):</span> <span class="co"># Groups (n=4, named as 'order'):</span>
<span class="co"># [1] "Caryophanales" "Enterobacterales" "Lactobacillales" "Pseudomonadales"</span> <span class="co"># [1] "Caryophanales" "Enterobacterales" "Lactobacillales" "Pseudomonadales"</span>
<span class="co"># Importance of components:</span> <span class="co"># Importance of components:</span>
<span class="co"># PC1 PC2 PC3 PC4 PC5 PC6 PC7</span> <span class="co"># PC1 PC2 PC3 PC4 PC5 PC6 PC7</span>
<span class="co"># Standard deviation 2.1539 1.6807 0.6138 0.33879 0.20808 0.03140 5.121e-17</span> <span class="co"># Standard deviation 2.1539 1.6807 0.6138 0.33879 0.20808 0.03140 5.674e-17</span>
<span class="co"># Proportion of Variance 0.5799 0.3531 0.0471 0.01435 0.00541 0.00012 0.000e+00</span> <span class="co"># Proportion of Variance 0.5799 0.3531 0.0471 0.01435 0.00541 0.00012 0.000e+00</span>
<span class="co"># Cumulative Proportion 0.5799 0.9330 0.9801 0.99446 0.99988 1.00000 1.000e+00</span></code></pre></div> <span class="co"># Cumulative Proportion 0.5799 0.9330 0.9801 0.99446 0.99988 1.00000 1.000e+00</span></code></pre></div>
<pre><code><span class="co"># Groups (n=4, named as 'order'):</span> <pre><code><span class="co"># Groups (n=4, named as 'order'):</span>
<span class="co"># [1] "Caryophanales" "Enterobacterales" "Lactobacillales" "Pseudomonadales"</span></code></pre> <span class="co"># [1] "Caryophanales" "Enterobacterales" "Lactobacillales" "Pseudomonadales"</span></code></pre>
<p>Good news. The first two components explain a total of 93.3% of the variance (see the PC1 and PC2 values of the <em>Proportion of Variance</em>. We can create a so-called biplot with the base R <code><a href="https://rdrr.io/r/stats/biplot.html" class="external-link">biplot()</a></code> function, to see which antimicrobial resistance per drug explain the difference per microorganism.</p> <p>Good news. The first two components explain a total of 93.3% of the
variance (see the PC1 and PC2 values of the <em>Proportion of
Variance</em>. We can create a so-called biplot with the base R
<code><a href="https://rdrr.io/r/stats/biplot.html" class="external-link">biplot()</a></code> function, to see which antimicrobial resistance
per drug explain the difference per microorganism.</p>
</div> </div>
<div class="section level1"> <div class="section level2">
<h1 id="plotting-the-results">Plotting the results<a class="anchor" aria-label="anchor" href="#plotting-the-results"></a> <h2 id="plotting-the-results">Plotting the results<a class="anchor" aria-label="anchor" href="#plotting-the-results"></a>
</h1> </h2>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/stats/biplot.html" class="external-link">biplot</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></code></pre></div> <code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/stats/biplot.html" class="external-link">biplot</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></code></pre></div>
<p><img src="PCA_files/figure-html/unnamed-chunk-5-1.png" width="750"></p> <p><img src="PCA_files/figure-html/unnamed-chunk-5-1.png" width="750"></p>
<p>But we cant see the explanation of the points. Perhaps this works better with our new <code><a href="../reference/ggplot_pca.html">ggplot_pca()</a></code> function, that automatically adds the right labels and even groups:</p> <p>But we cant see the explanation of the points. Perhaps this works
better with our new <code><a href="../reference/ggplot_pca.html">ggplot_pca()</a></code> function, that
automatically adds the right labels and even groups:</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/ggplot_pca.html">ggplot_pca</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></code></pre></div> <code class="sourceCode R"><span class="fu"><a href="../reference/ggplot_pca.html">ggplot_pca</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></code></pre></div>
<p><img src="PCA_files/figure-html/unnamed-chunk-6-1.png" width="750"></p> <p><img src="PCA_files/figure-html/unnamed-chunk-6-1.png" width="750"></p>
@ -340,7 +353,7 @@
<div class="pkgdown"> <div class="pkgdown">
<p></p> <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p> <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
</div> </div>
</footer> </footer>

View File

@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 93 KiB

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -44,7 +44,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9008</span>
</span> </span>
</div> </div>
@ -58,7 +58,7 @@
</a> </a>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span> <span class="fa fa-question-circle"></span>
How to How to
@ -189,9 +189,10 @@
<div class="col-md-9 contents"> <div class="col-md-9 contents">
<div class="page-header toc-ignore"> <div class="page-header toc-ignore">
<h1 data-toc-skip>How to import data from SPSS / SAS / Stata</h1> <h1 data-toc-skip>How to import data from SPSS / SAS / Stata</h1>
<h4 data-toc-skip class="author">Dr. Matthijs Berends</h4> <h4 data-toc-skip class="author">Dr. Matthijs
Berends</h4>
<h4 data-toc-skip class="date">23 December 2021</h4> <h4 data-toc-skip class="date">11 mei 2022</h4>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/SPSS.Rmd" class="external-link"><code>vignettes/SPSS.Rmd</code></a></small> <small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/SPSS.Rmd" class="external-link"><code>vignettes/SPSS.Rmd</code></a></small>
<div class="hidden name"><code>SPSS.Rmd</code></div> <div class="hidden name"><code>SPSS.Rmd</code></div>
@ -203,45 +204,135 @@
<div class="section level2"> <div class="section level2">
<h2 id="spss-sas-stata">SPSS / SAS / Stata<a class="anchor" aria-label="anchor" href="#spss-sas-stata"></a> <h2 id="spss-sas-stata">SPSS / SAS / Stata<a class="anchor" aria-label="anchor" href="#spss-sas-stata"></a>
</h2> </h2>
<p>SPSS (Statistical Package for the Social Sciences) is probably the most well-known software package for statistical analysis. SPSS is easier to learn than R, because in SPSS you only have to click a menu to run parts of your analysis. Because of its user-friendliness, it is taught at universities and particularly useful for students who are new to statistics. From my experience, I would guess that pretty much all (bio)medical students know it at the time they graduate. SAS and Stata are comparable statistical packages popular in big industries.</p> <p>SPSS (Statistical Package for the Social Sciences) is probably the
most well-known software package for statistical analysis. SPSS is
easier to learn than R, because in SPSS you only have to click a menu to
run parts of your analysis. Because of its user-friendliness, it is
taught at universities and particularly useful for students who are new
to statistics. From my experience, I would guess that pretty much all
(bio)medical students know it at the time they graduate. SAS and Stata
are comparable statistical packages popular in big industries.</p>
</div> </div>
<div class="section level2"> <div class="section level2">
<h2 id="compared-to-r">Compared to R<a class="anchor" aria-label="anchor" href="#compared-to-r"></a> <h2 id="compared-to-r">Compared to R<a class="anchor" aria-label="anchor" href="#compared-to-r"></a>
</h2> </h2>
<p>As said, SPSS is easier to learn than R. But SPSS, SAS and Stata come with major downsides when comparing it with R:</p> <p>As said, SPSS is easier to learn than R. But SPSS, SAS and Stata come
with major downsides when comparing it with R:</p>
<ul> <ul>
<li> <li>
<p><strong>R is highly modular.</strong></p> <p><strong>R is highly modular.</strong></p>
<p>The <a href="https://cran.r-project.org/" class="external-link">official R network (CRAN)</a> features more than 16,000 packages at the time of writing, our <code>AMR</code> package being one of them. All these packages were peer-reviewed before publication. Aside from this official channel, there are also developers who choose not to submit to CRAN, but rather keep it on their own public repository, like GitHub. So there may even be a lot more than 14,000 packages out there.</p> <p>The <a href="https://cran.r-project.org/" class="external-link">official R network
<p>Bottom line is, you can really extend it yourself or ask somebody to do this for you. Take for example our <code>AMR</code> package. Among other things, it adds reliable reference data to R to help you with the data cleaning and analysis. SPSS, SAS and Stata will never know what a valid MIC value is or what the Gram stain of <em>E. coli</em> is. Or that all species of <em>Klebiella</em> are resistant to amoxicillin and that Floxapen<sup>®</sup> is a trade name of flucloxacillin. These facts and properties are often needed to clean existing data, which would be very inconvenient in a software package without reliable reference data. See below for a demonstration.</p> (CRAN)</a> features more than 16,000 packages at the time of writing,
our <code>AMR</code> package being one of them. All these packages were
peer-reviewed before publication. Aside from this official channel,
there are also developers who choose not to submit to CRAN, but rather
keep it on their own public repository, like GitHub. So there may even
be a lot more than 14,000 packages out there.</p>
<p>Bottom line is, you can really extend it yourself or ask somebody to
do this for you. Take for example our <code>AMR</code> package. Among
other things, it adds reliable reference data to R to help you with the
data cleaning and analysis. SPSS, SAS and Stata will never know what a
valid MIC value is or what the Gram stain of <em>E. coli</em> is. Or
that all species of <em>Klebiella</em> are resistant to amoxicillin and
that Floxapen<sup>®</sup> is a trade name of flucloxacillin. These facts
and properties are often needed to clean existing data, which would be
very inconvenient in a software package without reliable reference data.
See below for a demonstration.</p>
</li> </li>
<li> <li>
<p><strong>R is extremely flexible.</strong></p> <p><strong>R is extremely flexible.</strong></p>
<p>Because you write the syntax yourself, you can do anything you want. The flexibility in transforming, arranging, grouping and summarising data, or drawing plots, is endless - with SPSS, SAS or Stata you are bound to their algorithms and format styles. They may be a bit flexible, but you can probably never create that very specific publication-ready plot without using other (paid) software. If you sometimes write syntaxes in SPSS to run a complete analysis or to automate some of your work, you could do this a lot less time in R. You will notice that writing syntaxes in R is a lot more nifty and clever than in SPSS. Still, as working with any statistical package, you will have to have knowledge about what you are doing (statistically) and what you are willing to accomplish.</p> <p>Because you write the syntax yourself, you can do anything you want.
The flexibility in transforming, arranging, grouping and summarising
data, or drawing plots, is endless - with SPSS, SAS or Stata you are
bound to their algorithms and format styles. They may be a bit flexible,
but you can probably never create that very specific publication-ready
plot without using other (paid) software. If you sometimes write
syntaxes in SPSS to run a complete analysis or to automate some of
your work, you could do this a lot less time in R. You will notice that
writing syntaxes in R is a lot more nifty and clever than in SPSS.
Still, as working with any statistical package, you will have to have
knowledge about what you are doing (statistically) and what you are
willing to accomplish.</p>
</li> </li>
<li> <li>
<p><strong>R can be easily automated.</strong></p> <p><strong>R can be easily automated.</strong></p>
<p>Over the last years, <a href="https://rmarkdown.rstudio.com/" class="external-link">R Markdown</a> has really made an interesting development. With R Markdown, you can very easily produce reports, whether the format has to be Word, PowerPoint, a website, a PDF document or just the raw data to Excel. It even allows the use of a reference file containing the layout style (e.g. fonts and colours) of your organisation. I use this a lot to generate weekly and monthly reports automatically. Just write the code once and enjoy the automatically updated reports at any interval you like.</p> <p>Over the last years, <a href="https://rmarkdown.rstudio.com/" class="external-link">R
<p>For an even more professional environment, you could create <a href="https://shiny.rstudio.com/" class="external-link">Shiny apps</a>: live manipulation of data using a custom made website. The webdesign knowledge needed (JavaScript, CSS, HTML) is almost <em>zero</em>.</p> Markdown</a> has really made an interesting development. With R
Markdown, you can very easily produce reports, whether the format has to
be Word, PowerPoint, a website, a PDF document or just the raw data to
Excel. It even allows the use of a reference file containing the layout
style (e.g. fonts and colours) of your organisation. I use this a lot to
generate weekly and monthly reports automatically. Just write the code
once and enjoy the automatically updated reports at any interval you
like.</p>
<p>For an even more professional environment, you could create <a href="https://shiny.rstudio.com/" class="external-link">Shiny apps</a>: live manipulation of
data using a custom made website. The webdesign knowledge needed
(JavaScript, CSS, HTML) is almost <em>zero</em>.</p>
</li> </li>
<li> <li>
<p><strong>R has a huge community.</strong></p> <p><strong>R has a huge community.</strong></p>
<p>Many R users just ask questions on websites like <a href="https://stackoverflow.com" class="external-link">StackOverflow.com</a>, the largest online community for programmers. At the time of writing, <a href="https://stackoverflow.com/questions/tagged/r?sort=votes" class="external-link">430,288 R-related questions</a> have already been asked on this platform (that covers questions and answers for any programming language). In my own experience, most questions are answered within a couple of minutes.</p> <p>Many R users just ask questions on websites like <a href="https://stackoverflow.com" class="external-link">StackOverflow.com</a>, the largest
online community for programmers. At the time of writing, <a href="https://stackoverflow.com/questions/tagged/r?sort=votes" class="external-link">447,735
R-related questions</a> have already been asked on this platform (that
covers questions and answers for any programming language). In my own
experience, most questions are answered within a couple of
minutes.</p>
</li> </li>
<li> <li>
<p><strong>R understands any data type, including SPSS/SAS/Stata.</strong></p> <p><strong>R understands any data type, including
<p>And thats not vice versa Im afraid. You can import data from any source into R. For example from SPSS, SAS and Stata (<a href="https://haven.tidyverse.org/" class="external-link">link</a>), from Minitab, Epi Info and EpiData (<a href="https://cran.r-project.org/package=foreign" class="external-link">link</a>), from Excel (<a href="https://readxl.tidyverse.org/" class="external-link">link</a>), from flat files like CSV, TXT or TSV (<a href="https://readr.tidyverse.org/" class="external-link">link</a>), or directly from databases and datawarehouses from anywhere on the world (<a href="https://dbplyr.tidyverse.org/" class="external-link">link</a>). You can even scrape websites to download tables that are live on the internet (<a href="https://github.com/hadley/rvest" class="external-link">link</a>) or get the results of an API call and transform it into data in only one command (<a href="https://github.com/Rdatatable/data.table/wiki/Convenience-features-of-fread" class="external-link">link</a>).</p> SPSS/SAS/Stata.</strong></p>
<p>And the best part - you can export from R to most data formats as well. So you can import an SPSS file, do your analysis neatly in R and export the resulting tables to Excel files for sharing.</p> <p>And thats not vice versa Im afraid. You can import data from any
source into R. For example from SPSS, SAS and Stata (<a href="https://haven.tidyverse.org/" class="external-link">link</a>), from Minitab, Epi Info
and EpiData (<a href="https://cran.r-project.org/package=foreign" class="external-link">link</a>), from Excel
(<a href="https://readxl.tidyverse.org/" class="external-link">link</a>), from flat files like
CSV, TXT or TSV (<a href="https://readr.tidyverse.org/" class="external-link">link</a>), or
directly from databases and datawarehouses from anywhere on the world
(<a href="https://dbplyr.tidyverse.org/" class="external-link">link</a>). You can even scrape
websites to download tables that are live on the internet (<a href="https://github.com/hadley/rvest" class="external-link">link</a>) or get the results of
an API call and transform it into data in only one command (<a href="https://github.com/Rdatatable/data.table/wiki/Convenience-features-of-fread" class="external-link">link</a>).</p>
<p>And the best part - you can export from R to most data formats as
well. So you can import an SPSS file, do your analysis neatly in R and
export the resulting tables to Excel files for sharing.</p>
</li> </li>
<li> <li>
<p><strong>R is completely free and open-source.</strong></p> <p><strong>R is completely free and open-source.</strong></p>
<p>No strings attached. It was created and is being maintained by volunteers who believe that (data) science should be open and publicly available to everybody. SPSS, SAS and Stata are quite expensive. IBM SPSS Staticstics only comes with subscriptions nowadays, varying <a href="https://www.ibm.com/products/spss-statistics/pricing" class="external-link">between USD 1,300 and USD 8,500</a> per user <em>per year</em>. SAS Analytics Pro costs <a href="https://www.sas.com/store/products-solutions/sas-analytics-pro/prodPERSANL.html" class="external-link">around USD 10,000</a> per computer. Stata also has a business model with subscription fees, varying <a href="https://www.stata.com/order/new/bus/single-user-licenses/dl/" class="external-link">between USD 600 and USD 2,800</a> per computer per year, but lower prices come with a limitation of the number of variables you can work with. And still they do not offer the above benefits of R.</p> <p>No strings attached. It was created and is being maintained by
<p>If you are working at a midsized or small company, you can save it tens of thousands of dollars by using R instead of e.g. SPSS - gaining even more functions and flexibility. And all R enthousiasts can do as much PR as they want (like I do here), because nobody is officially associated with or affiliated by R. It is really free.</p> volunteers who believe that (data) science should be open and publicly
available to everybody. SPSS, SAS and Stata are quite expensive. IBM
SPSS Staticstics only comes with subscriptions nowadays, varying <a href="https://www.ibm.com/products/spss-statistics/pricing" class="external-link">between USD
1,300 and USD 8,500</a> per user <em>per year</em>. SAS Analytics Pro
costs <a href="https://www.sas.com/store/products-solutions/sas-analytics-pro/prodPERSANL.html" class="external-link">around
USD 10,000</a> per computer. Stata also has a business model with
subscription fees, varying <a href="https://www.stata.com/order/new/bus/single-user-licenses/dl/" class="external-link">between
USD 600 and USD 2,800</a> per computer per year, but lower prices come
with a limitation of the number of variables you can work with. And
still they do not offer the above benefits of R.</p>
<p>If you are working at a midsized or small company, you can save it
tens of thousands of dollars by using R instead of e.g. SPSS - gaining
even more functions and flexibility. And all R enthousiasts can do as
much PR as they want (like I do here), because nobody is officially
associated with or affiliated by R. It is really free.</p>
</li> </li>
<li> <li>
<p><strong>R is (nowadays) the preferred analysis software in academic papers.</strong></p> <p><strong>R is (nowadays) the preferred analysis software in
<p>At present, R is among the world most powerful statistical languages, and it is generally very popular in science (Bollmann <em>et al.</em>, 2017). For all the above reasons, the number of references to R as an analysis method in academic papers <a href="https://r4stats.com/2014/08/20/r-passes-spss-in-scholarly-use-stata-growing-rapidly/" class="external-link">is rising continuously</a> and has even surpassed SPSS for academic use (Muenchen, 2014).</p> academic papers.</strong></p>
<p>I believe that the thing with SPSS is, that it has always had a great user interface which is very easy to learn and use. Back when they developed it, they had very little competition, let alone from R. R didnt even had a professional user interface until the last decade (called RStudio, see below). How people used R between the nineties and 2010 is almost completely incomparable to how R is being used now. The language itself <a href="https://www.tidyverse.org/packages/" class="external-link">has been restyled completely</a> by volunteers who are dedicated professionals in the field of data science. SPSS was great when there was nothing else that could compete. But now in 2021, I dont see any reason why SPSS would be of any better use than R.</p> <p>At present, R is among the world most powerful statistical languages,
and it is generally very popular in science (Bollmann <em>et al.</em>,
2017). For all the above reasons, the number of references to R as an
analysis method in academic papers <a href="https://r4stats.com/2014/08/20/r-passes-spss-in-scholarly-use-stata-growing-rapidly/" class="external-link">is
rising continuously</a> and has even surpassed SPSS for academic use
(Muenchen, 2014).</p>
<p>I believe that the thing with SPSS is, that it has always had a great
user interface which is very easy to learn and use. Back when they
developed it, they had very little competition, let alone from R. R
didnt even had a professional user interface until the last decade
(called RStudio, see below). How people used R between the nineties and
2010 is almost completely incomparable to how R is being used now. The
language itself <a href="https://www.tidyverse.org/packages/" class="external-link">has been
restyled completely</a> by volunteers who are dedicated professionals in
the field of data science. SPSS was great when there was nothing else
that could compete. But now in 2022, I dont see any reason why SPSS
would be of any better use than R.</p>
</li> </li>
</ul> </ul>
<p>To demonstrate the first point:</p> <p>To demonstrate the first point:</p>
@ -285,13 +376,23 @@
<div class="section level3"> <div class="section level3">
<h3 id="rstudio">RStudio<a class="anchor" aria-label="anchor" href="#rstudio"></a> <h3 id="rstudio">RStudio<a class="anchor" aria-label="anchor" href="#rstudio"></a>
</h3> </h3>
<p>To work with R, probably the best option is to use <a href="https://www.rstudio.com/products/rstudio/" class="external-link">RStudio</a>. It is an open-source and free desktop environment which not only allows you to run R code, but also supports project management, version management, package management and convenient import menus to work with other data sources. You can also install <a href="https://www.rstudio.com/products/rstudio/" class="external-link">RStudio Server</a> on a private or corporate server, which brings nothing less than the complete RStudio software to you as a website (at home or at work).</p> <p>To work with R, probably the best option is to use <a href="https://www.rstudio.com/products/rstudio/" class="external-link">RStudio</a>. It is an
<p>To import a data file, just click <em>Import Dataset</em> in the Environment tab:</p> open-source and free desktop environment which not only allows you to
run R code, but also supports project management, version management,
package management and convenient import menus to work with other data
sources. You can also install <a href="https://www.rstudio.com/products/rstudio/" class="external-link">RStudio Server</a> on a
private or corporate server, which brings nothing less than the complete
RStudio software to you as a website (at home or at work).</p>
<p>To import a data file, just click <em>Import Dataset</em> in the
Environment tab:</p>
<p><img src="https://github.com/msberends/AMR/raw/main/docs/import1.png"></p> <p><img src="https://github.com/msberends/AMR/raw/main/docs/import1.png"></p>
<p>If additional packages are needed, RStudio will ask you if they should be installed on beforehand.</p> <p>If additional packages are needed, RStudio will ask you if they
<p>In the the window that opens, you can define all options (parameters) that should be used for import and youre ready to go:</p> should be installed on beforehand.</p>
<p>In the the window that opens, you can define all options (parameters)
that should be used for import and youre ready to go:</p>
<p><img src="https://github.com/msberends/AMR/raw/main/docs/import2.png"></p> <p><img src="https://github.com/msberends/AMR/raw/main/docs/import2.png"></p>
<p>If you want named variables to be imported as factors so it resembles SPSS more, use <code><a href="https://haven.tidyverse.org/reference/as_factor.html" class="external-link">as_factor()</a></code>.</p> <p>If you want named variables to be imported as factors so it resembles
SPSS more, use <code><a href="https://haven.tidyverse.org/reference/as_factor.html" class="external-link">as_factor()</a></code>.</p>
<p>The difference is this:</p> <p>The difference is this:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">SPSS_data</span> <code class="sourceCode R"><span class="va">SPSS_data</span>
@ -329,7 +430,8 @@
<div class="section level3"> <div class="section level3">
<h3 id="base-r">Base R<a class="anchor" aria-label="anchor" href="#base-r"></a> <h3 id="base-r">Base R<a class="anchor" aria-label="anchor" href="#base-r"></a>
</h3> </h3>
<p>To import data from SPSS, SAS or Stata, you can use the <a href="https://haven.tidyverse.org/" class="external-link">great <code>haven</code> package</a> yourself:</p> <p>To import data from SPSS, SAS or Stata, you can use the <a href="https://haven.tidyverse.org/" class="external-link">great <code>haven</code> package</a>
yourself:</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># download and install the latest version:</span> <code class="sourceCode R"><span class="co"># download and install the latest version:</span>
<span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html" class="external-link">install.packages</a></span><span class="op">(</span><span class="st">"haven"</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html" class="external-link">install.packages</a></span><span class="op">(</span><span class="st">"haven"</span><span class="op">)</span>
@ -414,7 +516,7 @@
<div class="pkgdown"> <div class="pkgdown">
<p></p> <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p> <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
</div> </div>
</footer> </footer>

View File

@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -44,7 +44,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9008</span>
</span> </span>
</div> </div>
@ -58,7 +58,7 @@
</a> </a>
</li> </li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span> <span class="fa fa-question-circle"></span>
How to How to
@ -201,26 +201,43 @@
<div class="section level3"> <div class="section level3">
<h3 id="import-of-data">Import of data<a class="anchor" aria-label="anchor" href="#import-of-data"></a> <h3 id="import-of-data">Import of data<a class="anchor" aria-label="anchor" href="#import-of-data"></a>
</h3> </h3>
<p>This tutorial assumes you already imported the WHONET data with e.g. the <a href="https://readxl.tidyverse.org/" class="external-link"><code>readxl</code> package</a>. In RStudio, this can be done using the menu button Import Dataset in the tab Environment. Choose the option From Excel and select your exported file. Make sure date fields are imported correctly.</p> <p>This tutorial assumes you already imported the WHONET data with
e.g. the <a href="https://readxl.tidyverse.org/" class="external-link"><code>readxl</code>
package</a>. In RStudio, this can be done using the menu button Import
Dataset in the tab Environment. Choose the option From Excel and
select your exported file. Make sure date fields are imported
correctly.</p>
<p>An example syntax could look like this:</p> <p>An example syntax could look like this:</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://readxl.tidyverse.org" class="external-link">readxl</a></span><span class="op">)</span> <code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://readxl.tidyverse.org" class="external-link">readxl</a></span><span class="op">)</span>
<span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://readxl.tidyverse.org/reference/read_excel.html" class="external-link">read_excel</a></span><span class="op">(</span>path <span class="op">=</span> <span class="st">"path/to/your/file.xlsx"</span><span class="op">)</span></code></pre></div> <span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://readxl.tidyverse.org/reference/read_excel.html" class="external-link">read_excel</a></span><span class="op">(</span>path <span class="op">=</span> <span class="st">"path/to/your/file.xlsx"</span><span class="op">)</span></code></pre></div>
<p>This package comes with an <a href="https://msberends.github.io/AMR/reference/WHONET.html">example data set <code>WHONET</code></a>. We will use it for this analysis.</p> <p>This package comes with an <a href="https://msberends.github.io/AMR/reference/WHONET.html">example
data set <code>WHONET</code></a>. We will use it for this analysis.</p>
</div> </div>
<div class="section level3"> <div class="section level3">
<h3 id="preparation">Preparation<a class="anchor" aria-label="anchor" href="#preparation"></a> <h3 id="preparation">Preparation<a class="anchor" aria-label="anchor" href="#preparation"></a>
</h3> </h3>
<p>First, load the relevant packages if you did not yet did this. I use the tidyverse for all of my analyses. All of them. If you dont know it yet, I suggest you read about it on their website: <a href="https://www.tidyverse.org/" class="external-link uri">https://www.tidyverse.org/</a>.</p> <p>First, load the relevant packages if you did not yet did this. I use
the tidyverse for all of my analyses. All of them. If you dont know it
yet, I suggest you read about it on their website: <a href="https://www.tidyverse.org/" class="external-link uri">https://www.tidyverse.org/</a>.</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span> <span class="co"># part of tidyverse</span> <code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span> <span class="co"># part of tidyverse</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span> <span class="co"># part of tidyverse</span> <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span> <span class="co"># part of tidyverse</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR">AMR</a></span><span class="op">)</span> <span class="co"># this package</span> <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR/">AMR</a></span><span class="op">)</span> <span class="co"># this package</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/msberends/cleaner" class="external-link">cleaner</a></span><span class="op">)</span> <span class="co"># to create frequency tables</span></code></pre></div> <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/msberends/cleaner" class="external-link">cleaner</a></span><span class="op">)</span> <span class="co"># to create frequency tables</span></code></pre></div>
<p>We will have to transform some variables to simplify and automate the analysis:</p> <p>We will have to transform some variables to simplify and automate the
analysis:</p>
<ul> <ul>
<li>Microorganisms should be transformed to our own microorganism codes (called an <code>mo</code>) using <a href="https://msberends.github.io/AMR/reference/catalogue_of_life">our Catalogue of Life reference data set</a>, which contains all ~70,000 microorganisms from the taxonomic kingdoms Bacteria, Fungi and Protozoa. We do the tranformation with <code><a href="../reference/as.mo.html">as.mo()</a></code>. This function also recognises almost all WHONET abbreviations of microorganisms.</li> <li>Microorganisms should be transformed to our own microorganism codes
<li>Antimicrobial results or interpretations have to be clean and valid. In other words, they should only contain values <code>"S"</code>, <code>"I"</code> or <code>"R"</code>. That is exactly where the <code><a href="../reference/as.rsi.html">as.rsi()</a></code> function is for.</li> (called an <code>mo</code>) using <a href="https://msberends.github.io/AMR/reference/catalogue_of_life">our
Catalogue of Life reference data set</a>, which contains all ~70,000
microorganisms from the taxonomic kingdoms Bacteria, Fungi and Protozoa.
We do the tranformation with <code><a href="../reference/as.mo.html">as.mo()</a></code>. This function also
recognises almost all WHONET abbreviations of microorganisms.</li>
<li>Antimicrobial results or interpretations have to be clean and valid.
In other words, they should only contain values <code>"S"</code>,
<code>"I"</code> or <code>"R"</code>. That is exactly where the
<code><a href="../reference/as.rsi.html">as.rsi()</a></code> function is for.</li>
</ul> </ul>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># transform variables</span> <code class="sourceCode R"><span class="co"># transform variables</span>
@ -230,7 +247,9 @@
<span class="co"># transform everything from "AMP_ND10" to "CIP_EE" to the new `rsi` class</span> <span class="co"># transform everything from "AMP_ND10" to "CIP_EE" to the new `rsi` class</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html" class="external-link">mutate_at</a></span><span class="op">(</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html" class="external-link">vars</a></span><span class="op">(</span><span class="va">AMP_ND10</span><span class="op">:</span><span class="va">CIP_EE</span><span class="op">)</span>, <span class="va">as.rsi</span><span class="op">)</span></code></pre></div> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html" class="external-link">mutate_at</a></span><span class="op">(</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html" class="external-link">vars</a></span><span class="op">(</span><span class="va">AMP_ND10</span><span class="op">:</span><span class="va">CIP_EE</span><span class="op">)</span>, <span class="va">as.rsi</span><span class="op">)</span></code></pre></div>
<p>No errors or warnings, so all values are transformed succesfully.</p> <p>No errors or warnings, so all values are transformed succesfully.</p>
<p>We also created a package dedicated to data cleaning and checking, called the <code>cleaner</code> package. Its <code><a href="https://rdrr.io/pkg/cleaner/man/freq.html" class="external-link">freq()</a></code> function can be used to create frequency tables.</p> <p>We also created a package dedicated to data cleaning and checking,
called the <code>cleaner</code> package. Its <code><a href="https://rdrr.io/pkg/cleaner/man/freq.html" class="external-link">freq()</a></code>
function can be used to create frequency tables.</p>
<p>So lets check our data, with a couple of frequency tables:</p> <p>So lets check our data, with a couple of frequency tables:</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># our newly created `mo` variable, put in the mo_name() function</span> <code class="sourceCode R"><span class="co"># our newly created `mo` variable, put in the mo_name() function</span>
@ -238,11 +257,19 @@
<p><strong>Frequency table</strong></p> <p><strong>Frequency table</strong></p>
<p>Class: character<br> <p>Class: character<br>
Length: 500<br> Length: 500<br>
Available: 500 (100.0%, NA: 0 = 0.0%)<br> Available: 500 (100%, NA: 0 = 0%)<br>
Unique: 37</p> Unique: 37</p>
<p>Shortest: 11<br> <p>Shortest: 11<br>
Longest: 40</p> Longest: 40</p>
<table class="table"> <table class="table">
<colgroup>
<col width="4%">
<col width="47%">
<col width="7%">
<col width="10%">
<col width="13%">
<col width="15%">
</colgroup>
<thead><tr class="header"> <thead><tr class="header">
<th align="left"></th> <th align="left"></th>
<th align="left">Item</th> <th align="left">Item</th>
@ -334,7 +361,7 @@ Longest: 40</p>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<p>(omitted 27 entries, n = 56 [11.20%])</p> <p>(omitted 27 entries, n = 56 [11.2%])</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># our transformed antibiotic columns</span> <code class="sourceCode R"><span class="co"># our transformed antibiotic columns</span>
<span class="co"># amoxicillin/clavulanic acid (J01CR02) as an example</span> <span class="co"># amoxicillin/clavulanic acid (J01CR02) as an example</span>
@ -388,7 +415,8 @@ Drug group: Beta-lactams/penicillins<br>
<div class="section level3"> <div class="section level3">
<h3 id="a-first-glimpse-at-results">A first glimpse at results<a class="anchor" aria-label="anchor" href="#a-first-glimpse-at-results"></a> <h3 id="a-first-glimpse-at-results">A first glimpse at results<a class="anchor" aria-label="anchor" href="#a-first-glimpse-at-results"></a>
</h3> </h3>
<p>An easy <code>ggplot</code> will already give a lot of information, using the included <code><a href="../reference/ggplot_rsi.html">ggplot_rsi()</a></code> function:</p> <p>An easy <code>ggplot</code> will already give a lot of information,
using the included <code><a href="../reference/ggplot_rsi.html">ggplot_rsi()</a></code> function:</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">data</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <code class="sourceCode R"><span class="va">data</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">Country</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">Country</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
@ -413,7 +441,7 @@ Drug group: Beta-lactams/penicillins<br>
<div class="pkgdown"> <div class="pkgdown">
<p></p> <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p> <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
</div> </div>
</footer> </footer>

View File

@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 73 KiB

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

View File

@ -44,7 +44,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.0</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1</span>
</span> </span>
</div> </div>
@ -185,7 +185,7 @@
</header><div class="row"> </header><script src="benchmarks_files/accessible-code-block-0.0.1/empty-anchor.js"></script><div class="row">
<div class="col-md-9 contents"> <div class="col-md-9 contents">
<div class="page-header toc-ignore"> <div class="page-header toc-ignore">
<h1 data-toc-skip>Benchmarks</h1> <h1 data-toc-skip>Benchmarks</h1>
@ -202,7 +202,7 @@
<p>Using the <code>microbenchmark</code> package, we can review the calculation performance of this function. Its function <code><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark()</a></code> runs different input expressions independently of each other and measures their time-to-result.</p> <p>Using the <code>microbenchmark</code> package, we can review the calculation performance of this function. Its function <code><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark()</a></code> runs different input expressions independently of each other and measures their time-to-result.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/joshuaulrich/microbenchmark/" class="external-link">microbenchmark</a></span><span class="op">)</span> <code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/joshuaulrich/microbenchmark/" class="external-link">microbenchmark</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR">AMR</a></span><span class="op">)</span> <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR/">AMR</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></code></pre></div> <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></code></pre></div>
<p>In the next test, we try to coerce different input values into the microbial code of <em>Staphylococcus aureus</em>. Coercion is a computational process of forcing output based on an input. For microorganism names, coercing user input to taxonomically valid microorganism names is crucial to ensure correct interpretation and to enable grouping based on taxonomic properties.</p> <p>In the next test, we try to coerce different input values into the microbial code of <em>Staphylococcus aureus</em>. Coercion is a computational process of forcing output based on an input. For microorganism names, coercing user input to taxonomically valid microorganism names is crucial to ensure correct interpretation and to enable grouping based on taxonomic properties.</p>
<p>The actual result is the same every time: it returns its microorganism code <code>B_STPHY_AURS</code> (<em>B</em> stands for <em>Bacteria</em>, its taxonomic kingdom).</p> <p>The actual result is the same every time: it returns its microorganism code <code>B_STPHY_AURS</code> (<em>B</em> stands for <em>Bacteria</em>, its taxonomic kingdom).</p>
@ -222,23 +222,23 @@
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"MRSA"</span><span class="op">)</span>, <span class="co"># Methicillin Resistant S. aureus</span> <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"MRSA"</span><span class="op">)</span>, <span class="co"># Methicillin Resistant S. aureus</span>
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"VISA"</span><span class="op">)</span>, <span class="co"># Vancomycin Intermediate S. aureus</span> <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"VISA"</span><span class="op">)</span>, <span class="co"># Vancomycin Intermediate S. aureus</span>
times <span class="op">=</span> <span class="fl">25</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">25</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">S.aureus</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">2</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">S.aureus</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">2</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># as.mo("sau") 10.0 12.0 20.0 12.0 15.0 53 25</span> <span class="co"># as.mo("sau") 19.0 20.0 25.0 20.0 26.0 55 25</span>
<span class="co"># as.mo("stau") 49.0 54.0 72.0 58.0 91.0 97 25</span> <span class="co"># as.mo("stau") 94.0 95.0 110.0 100.0 130.0 140 25</span>
<span class="co"># as.mo("STAU") 50.0 54.0 71.0 57.0 90.0 110 25</span> <span class="co"># as.mo("STAU") 92.0 97.0 110.0 110.0 120.0 140 25</span>
<span class="co"># as.mo("staaur") 10.0 12.0 17.0 12.0 14.0 51 25</span> <span class="co"># as.mo("staaur") 19.0 19.0 24.0 20.0 21.0 56 25</span>
<span class="co"># as.mo("STAAUR") 10.0 12.0 17.0 12.0 14.0 54 25</span> <span class="co"># as.mo("STAAUR") 19.0 20.0 21.0 20.0 20.0 49 25</span>
<span class="co"># as.mo("S. aureus") 26.0 27.0 40.0 31.0 56.0 74 25</span> <span class="co"># as.mo("S. aureus") 54.0 57.0 72.0 64.0 86.0 96 25</span>
<span class="co"># as.mo("S aureus") 26.0 27.0 39.0 29.0 58.0 68 25</span> <span class="co"># as.mo("S aureus") 55.0 55.0 72.0 57.0 90.0 100 25</span>
<span class="co"># as.mo("Staphylococcus aureus") 3.5 3.9 6.6 4.1 4.8 38 25</span> <span class="co"># as.mo("Staphylococcus aureus") 5.6 5.7 8.5 5.8 6.2 40 25</span>
<span class="co"># as.mo("Staphylococcus aureus (MRSA)") 230.0 240.0 250.0 240.0 250.0 280 25</span> <span class="co"># as.mo("Staphylococcus aureus (MRSA)") 360.0 370.0 400.0 400.0 420.0 550 25</span>
<span class="co"># as.mo("Sthafilokkockus aaureuz") 180.0 190.0 200.0 190.0 200.0 290 25</span> <span class="co"># as.mo("Sthafilokkockus aaureuz") 280.0 290.0 300.0 300.0 320.0 350 25</span>
<span class="co"># as.mo("MRSA") 11.0 12.0 19.0 13.0 14.0 50 25</span> <span class="co"># as.mo("MRSA") 19.0 20.0 24.0 20.0 21.0 51 25</span>
<span class="co"># as.mo("VISA") 21.0 22.0 32.0 25.0 50.0 60 25</span></code></pre></div> <span class="co"># as.mo("VISA") 34.0 34.0 48.0 36.0 65.0 73 25</span></code></pre></div>
<p><img src="benchmarks_files/figure-html/unnamed-chunk-4-1.png" width="750"></p> <p><img src="benchmarks_files/figure-html/unnamed-chunk-4-1.png" width="750"></p>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 200 milliseconds, this is only 5 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations are up to 47 times slower to determine.</p> <p>In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 200 milliseconds, this is only 5 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations are up to 69 times slower to determine.</p>
<p>To improve performance, we implemented two important algorithms to save unnecessary calculations: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p> <p>To improve performance, we implemented two important algorithms to save unnecessary calculations: <strong>repetitive results</strong> and <strong>already precalculated results</strong>.</p>
<div class="section level3"> <div class="section level3">
<h3 id="repetitive-results">Repetitive results<a class="anchor" aria-label="anchor" href="#repetitive-results"></a> <h3 id="repetitive-results">Repetitive results<a class="anchor" aria-label="anchor" href="#repetitive-results"></a>
@ -258,8 +258,8 @@
<span class="co"># what do these values look like? They are of class &lt;mo&gt;:</span> <span class="co"># what do these values look like? They are of class &lt;mo&gt;:</span>
<span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>
<span class="co"># Class &lt;mo&gt;</span> <span class="co"># Class &lt;mo&gt;</span>
<span class="co"># [1] B_STPHY_AURS B_STRPT_EQNS B_KLBSL_PNMN B_STPHY_EPDR B_STPHY_AURS</span> <span class="co"># [1] B_ENTRBC_CLOC B_ESCHR_COLI B_STRPT_PYGN B_STPHY_AURS B_ESCHR_COLI </span>
<span class="co"># [6] B_CRYNB_STRT</span> <span class="co"># [6] B_STRPT_PNMN</span>
<span class="co"># as the example_isolates data set has 2,000 rows, we should have 2 million items</span> <span class="co"># as the example_isolates data set has 2,000 rows, we should have 2 million items</span>
<span class="fu"><a href="https://rdrr.io/r/base/length.html" class="external-link">length</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/length.html" class="external-link">length</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>
@ -272,11 +272,11 @@
<span class="co"># now let's see:</span> <span class="co"># now let's see:</span>
<span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>, <span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>,
times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># mo_name(x) 196 209 274 223 364 388 10</span></code></pre></div> <span class="co"># mo_name(x) 259 264 357 299 451 509 10</span></code></pre></div>
<p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.223 seconds. That is 112 nanoseconds on average. You only lose time on your unique input values.</p> <p>So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.299 seconds. That is 149 nanoseconds on average. You only lose time on your unique input values.</p>
</div> </div>
<div class="section level3"> <div class="section level3">
<h3 id="precalculated-results">Precalculated results<a class="anchor" aria-label="anchor" href="#precalculated-results"></a> <h3 id="precalculated-results">Precalculated results<a class="anchor" aria-label="anchor" href="#precalculated-results"></a>
@ -287,13 +287,13 @@
B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"S. aureus"</span><span class="op">)</span>, B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"S. aureus"</span><span class="op">)</span>,
C <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"Staphylococcus aureus"</span><span class="op">)</span>, C <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="st">"Staphylococcus aureus"</span><span class="op">)</span>,
times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 8.00 9.16 9.19 9.28 9.46 9.73 10</span> <span class="co"># A 11.90 12.10 13.0 13.50 13.70 13.80 10</span>
<span class="co"># B 23.40 27.20 32.60 27.90 28.10 80.20 10</span> <span class="co"># B 60.90 61.20 67.7 66.20 66.90 99.70 10</span>
<span class="co"># C 1.85 2.25 2.40 2.47 2.62 2.90 10</span></code></pre></div> <span class="co"># C 2.91 2.94 3.2 3.32 3.38 3.46 10</span></code></pre></div>
<p>So going from <code>mo_name("Staphylococcus aureus")</code> to <code>"Staphylococcus aureus"</code> takes 0.0025 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p> <p>So going from <code>mo_name("Staphylococcus aureus")</code> to <code>"Staphylococcus aureus"</code> takes 0.0033 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r"> <div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark</a></span><span class="op">(</span>A <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_species</a></span><span class="op">(</span><span class="st">"aureus"</span><span class="op">)</span>, <code class="sourceCode R"><span class="va">run_it</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html" class="external-link">microbenchmark</a></span><span class="op">(</span>A <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_species</a></span><span class="op">(</span><span class="st">"aureus"</span><span class="op">)</span>,
B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span><span class="op">(</span><span class="st">"Staphylococcus"</span><span class="op">)</span>, B <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span><span class="op">(</span><span class="st">"Staphylococcus"</span><span class="op">)</span>,
@ -304,17 +304,17 @@
G <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_phylum</a></span><span class="op">(</span><span class="st">"Firmicutes"</span><span class="op">)</span>, G <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_phylum</a></span><span class="op">(</span><span class="st">"Firmicutes"</span><span class="op">)</span>,
H <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_kingdom</a></span><span class="op">(</span><span class="st">"Bacteria"</span><span class="op">)</span>, H <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_kingdom</a></span><span class="op">(</span><span class="st">"Bacteria"</span><span class="op">)</span>,
times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">10</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">3</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 1.76 1.80 2.07 1.95 2.26 2.90 10</span> <span class="co"># A 2.92 2.93 3.02 2.94 3.02 3.40 10</span>
<span class="co"># B 1.69 1.73 1.90 1.81 2.03 2.48 10</span> <span class="co"># B 2.87 2.90 3.14 3.09 3.32 3.71 10</span>
<span class="co"># C 1.71 1.77 1.92 1.91 2.05 2.17 10</span> <span class="co"># C 2.91 2.94 3.15 3.12 3.33 3.46 10</span>
<span class="co"># D 1.68 1.71 1.76 1.76 1.82 1.88 10</span> <span class="co"># D 2.86 2.90 3.05 2.96 3.27 3.30 10</span>
<span class="co"># E 1.68 1.70 1.89 1.89 2.04 2.26 10</span> <span class="co"># E 2.87 2.88 3.03 2.96 3.16 3.29 10</span>
<span class="co"># F 1.67 1.75 1.93 1.89 2.11 2.35 10</span> <span class="co"># F 2.92 2.95 3.08 2.98 3.29 3.35 10</span>
<span class="co"># G 1.70 1.76 1.97 1.88 2.12 2.43 10</span> <span class="co"># G 2.89 2.96 3.04 2.99 3.11 3.29 10</span>
<span class="co"># H 1.67 1.71 1.83 1.75 1.98 2.14 10</span></code></pre></div> <span class="co"># H 2.85 2.95 3.11 3.08 3.31 3.38 10</span></code></pre></div>
<p>Of course, when running <code>mo_phylum("Firmicutes")</code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> anyway, there is no point in calculating the result. And because this package contains all phyla of all known bacteria, it can just return the initial value immediately.</p> <p>Of course, when running <code>mo_phylum("Firmicutes")</code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> anyway, there is no point in calculating the result. And because this package contains all phyla of all known bacteria, it can just return the initial value immediately.</p>
</div> </div>
<div class="section level3"> <div class="section level3">
@ -347,19 +347,19 @@
ru <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">CoNS</span>, language <span class="op">=</span> <span class="st">"ru"</span><span class="op">)</span>, ru <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">CoNS</span>, language <span class="op">=</span> <span class="st">"ru"</span><span class="op">)</span>,
sv <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">CoNS</span>, language <span class="op">=</span> <span class="st">"sv"</span><span class="op">)</span>, sv <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">CoNS</span>, language <span class="op">=</span> <span class="st">"sv"</span><span class="op">)</span>,
times <span class="op">=</span> <span class="fl">100</span><span class="op">)</span> times <span class="op">=</span> <span class="fl">100</span><span class="op">)</span>
<span class="fu"><a href="https://docs.ropensci.org/skimr/reference/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">4</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">run_it</span>, unit <span class="op">=</span> <span class="st">"ms"</span>, signif <span class="op">=</span> <span class="fl">4</span><span class="op">)</span>
<span class="co"># Unit: milliseconds</span> <span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span> <span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># da 1.9470 2.0220 2.190 2.0720 2.358 3.234 100</span> <span class="co"># da 3.546 3.643 4.072 3.704 3.832 35.930 100</span>
<span class="co"># de 1.9560 2.0330 3.649 2.1610 2.401 50.670 100</span> <span class="co"># de 3.597 3.659 4.422 3.734 3.839 36.400 100</span>
<span class="co"># en 0.8937 0.9124 1.022 0.9776 1.120 1.748 100</span> <span class="co"># en 1.672 1.726 1.804 1.767 1.794 2.259 100</span>
<span class="co"># es 1.9710 2.0290 2.216 2.1000 2.391 3.109 100</span> <span class="co"># es 3.609 3.685 4.496 3.760 3.843 36.540 100</span>
<span class="co"># fr 1.8280 1.8960 3.214 1.9420 2.237 71.550 100</span> <span class="co"># fr 3.484 3.567 3.725 3.654 3.713 6.281 100</span>
<span class="co"># it 1.9370 1.9970 2.163 2.0610 2.339 3.210 100</span> <span class="co"># it 3.523 3.615 4.419 3.720 3.787 36.720 100</span>
<span class="co"># nl 1.9710 2.0280 2.698 2.1110 2.421 49.340 100</span> <span class="co"># nl 3.614 3.676 3.805 3.732 3.838 4.703 100</span>
<span class="co"># pt 1.8920 1.9600 2.119 2.0200 2.261 3.265 100</span> <span class="co"># pt 3.512 3.595 4.077 3.659 3.789 37.310 100</span>
<span class="co"># ru 1.8630 1.9420 2.779 2.0270 2.335 66.660 100</span> <span class="co"># ru 3.556 3.647 4.057 3.680 3.812 35.230 100</span>
<span class="co"># sv 1.8680 1.9190 4.062 1.9890 2.263 78.870 100</span></code></pre></div> <span class="co"># sv 3.540 3.642 4.093 3.732 3.803 36.340 100</span></code></pre></div>
<p>Currently supported languages are Danish, Dutch, English, French, German, Italian, Portuguese, Russian, Spanish and Swedish.</p> <p>Currently supported languages are Danish, Dutch, English, French, German, Italian, Portuguese, Russian, Spanish and Swedish.</p>
</div> </div>
</div> </div>
@ -379,7 +379,7 @@
<div class="pkgdown"> <div class="pkgdown">
<p></p> <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p> <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.2.</p>
</div> </div>
</footer> </footer>

View File

@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 78 KiB

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
// Hide empty <a> tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
// v0.0.1
// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
document.addEventListener('DOMContentLoaded', function() {
const codeList = document.getElementsByClassName("sourceCode");
for (var i = 0; i < codeList.length; i++) {
var linkList = codeList[i].getElementsByTagName('a');
for (var j = 0; j < linkList.length; j++) {
if (linkList[j].innerHTML === "") {
linkList[j].setAttribute('aria-hidden', 'true');
}
}
}
});

View File

@ -1,12 +0,0 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

Some files were not shown because too many files have changed in this diff Show More