1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-27 08:06:13 +01:00

improve as.mo()

This commit is contained in:
dr. M.S. (Matthijs) Berends 2023-05-24 15:55:53 +02:00
parent 3018fb87a9
commit 0bcf55d3b6
14 changed files with 76 additions and 22 deletions

View File

@ -30,6 +30,7 @@
^vignettes/datasets\.Rmd$ ^vignettes/datasets\.Rmd$
^vignettes/EUCAST\.Rmd$ ^vignettes/EUCAST\.Rmd$
^vignettes/MDR\.Rmd$ ^vignettes/MDR\.Rmd$
^vignettes/other_pkg.*\.Rmd$
^vignettes/PCA\.Rmd$ ^vignettes/PCA\.Rmd$
^vignettes/resistance_predict\.Rmd$ ^vignettes/resistance_predict\.Rmd$
^vignettes/SPSS\.Rmd$ ^vignettes/SPSS\.Rmd$

View File

@ -65,7 +65,11 @@ jobs:
- name: Set up R dependencies - name: Set up R dependencies
uses: r-lib/actions/setup-r-dependencies@v2 uses: r-lib/actions/setup-r-dependencies@v2
with: with:
extra-packages: any::pkgdown # add extra packages for website articles:
extra-packages: |
any::pkgdown
any::tidymodels
any::data.table
# Send updates to repo using GH Actions bot # Send updates to repo using GH Actions bot
- name: Create website in separate branch - name: Create website in separate branch

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 2.0.0.9018 Version: 2.0.0.9019
Date: 2023-05-17 Date: 2023-05-24
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

View File

@ -1,4 +1,4 @@
# AMR 2.0.0.9018 # AMR 2.0.0.9019
## Changed ## Changed
* Added oxygen tolerance to over 25,000 bacteria in the `microorganisms` data set * Added oxygen tolerance to over 25,000 bacteria in the `microorganisms` data set
@ -12,6 +12,7 @@
* Fixed some WHONET codes for microorganisms and consequently a couple of entries in `clinical_breakpoints` * Fixed some WHONET codes for microorganisms and consequently a couple of entries in `clinical_breakpoints`
* Fixed a bug for `as.mo()` that led to coercion of `NA` values when using custom microorganism codes * Fixed a bug for `as.mo()` that led to coercion of `NA` values when using custom microorganism codes
* Fixed usage of `icu_exclude` in `first_isolates()` * Fixed usage of `icu_exclude` in `first_isolates()`
* Improved `as.mo()` algorithm for searching on only species names
# AMR 2.0.0 # AMR 2.0.0

View File

@ -69,7 +69,7 @@
#' ab_atc_group2("AMX") #' ab_atc_group2("AMX")
#' ab_url("AMX") #' ab_url("AMX")
#' #'
#' # smart lowercase tranformation #' # smart lowercase transformation
#' ab_name(x = c("AMC", "PLB")) #' ab_name(x = c("AMC", "PLB"))
#' ab_name(x = c("AMC", "PLB"), tolower = TRUE) #' ab_name(x = c("AMC", "PLB"), tolower = TRUE)
#' #'

View File

@ -61,7 +61,7 @@
#' av_group("ACI") #' av_group("ACI")
#' av_url("ACI") #' av_url("ACI")
#' #'
#' # smart lowercase tranformation #' # lowercase transformation
#' av_name(x = c("ACI", "VALA")) #' av_name(x = c("ACI", "VALA"))
#' av_name(x = c("ACI", "VALA"), tolower = TRUE) #' av_name(x = c("ACI", "VALA"), tolower = TRUE)
#' #'

View File

@ -191,13 +191,14 @@ first_isolate <- function(x = NULL,
} }
meet_criteria(col_specimen, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) meet_criteria(col_specimen, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x))
if (is.logical(col_icu)) { if (is.logical(col_icu)) {
meet_criteria(col_icu, allow_class = "logical", has_length = c(1, nrow(x)), allow_NA = TRUE) meet_criteria(col_icu, allow_class = "logical", has_length = c(1, nrow(x)), allow_NA = TRUE, allow_NULL = TRUE)
x$newvar_is_icu <- col_icu x$newvar_is_icu <- col_icu
} else if (!is.null(col_icu)) { } else if (!is.null(col_icu)) {
# add "logical" to the allowed classes here, since it may give an error in certain user input, and should then also say that logicals can be used too
meet_criteria(col_icu, allow_class = c("character", "logical"), has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) meet_criteria(col_icu, allow_class = c("character", "logical"), has_length = 1, allow_NULL = TRUE, is_in = colnames(x))
x$newvar_is_icu <- x[, col_icu, drop = TRUE] x$newvar_is_icu <- x[, col_icu, drop = TRUE]
} else { } else {
x$newvar_is_icu <- NA_real_ x$newvar_is_icu <- NA
} }
# method # method
method <- coerce_method(method) method <- coerce_method(method)

11
R/mo.R
View File

@ -281,9 +281,16 @@ as.mo <- function(x,
x_parts <- strsplit(gsub("-", " ", x_out, fixed = TRUE), " ", fixed = TRUE)[[1]] x_parts <- strsplit(gsub("-", " ", x_out, fixed = TRUE), " ", fixed = TRUE)[[1]]
# do a pre-match on first character (and if it contains a space, first chars of first two terms) # do a pre-match on first character (and if it contains a space, first chars of first two terms)
if (length(x_parts) %in% c(2, 3)) { if (length(x_parts) == 1) {
# for genus or species or subspecies
filtr <- which(AMR_env$MO_lookup$full_first == substr(x_parts, 1, 1) |
AMR_env$MO_lookup$species_first == substr(x_parts, 1, 1) |
AMR_env$MO_lookup$subspecies_first == substr(x_parts, 1, 1))
} else if (length(x_parts) %in% c(2, 3)) {
# for genus + species + subspecies # for genus + species + subspecies
filtr <- which(AMR_env$MO_lookup$full_first == substr(x_parts[1], 1, 1) & (AMR_env$MO_lookup$species_first == substr(x_parts[2], 1, 1) | AMR_env$MO_lookup$subspecies_first == substr(x_parts[2], 1, 1))) filtr <- which(AMR_env$MO_lookup$full_first == substr(x_parts[1], 1, 1) &
(AMR_env$MO_lookup$species_first == substr(x_parts[2], 1, 1) |
AMR_env$MO_lookup$subspecies_first == substr(x_parts[2], 1, 1)))
} else if (length(x_parts) > 3) { } else if (length(x_parts) > 3) {
first_chars <- paste0("(^| )", "[", paste(substr(x_parts, 1, 1), collapse = ""), "]") first_chars <- paste0("(^| )", "[", paste(substr(x_parts, 1, 1), collapse = ""), "]")
filtr <- which(AMR_env$MO_lookup$full_first %like_case% first_chars) filtr <- which(AMR_env$MO_lookup$full_first %like_case% first_chars)

View File

@ -759,7 +759,7 @@ as_sir_method <- function(method_short,
if (is.null(mo)) { if (is.null(mo)) {
stop_("No information was supplied about the microorganisms (missing argument `mo` and no column of class 'mo' found). See ?as.sir.\n\n", stop_("No information was supplied about the microorganisms (missing argument `mo` and no column of class 'mo' found). See ?as.sir.\n\n",
"To transform certain columns with e.g. mutate(), use `data %>% mutate(across(..., as.sir, mo = x))`, where x is your column with microorganisms.\n", "To transform certain columns with e.g. mutate(), use `data %>% mutate(across(..., as.sir, mo = x))`, where x is your column with microorganisms.\n",
"To tranform all ", method_long, " in a data set, use `data %>% as.sir()` or `data %>% mutate_if(is.", method_short, ", as.sir)`.", "To transform all ", method_long, " in a data set, use `data %>% as.sir()` or `data %>% mutate_if(is.", method_short, ", as.sir)`.",
call = FALSE call = FALSE
) )
} }

View File

@ -70,9 +70,9 @@ home:
navbar: navbar:
title: "AMR (for R)" title: "AMR (for R)"
left: left:
- text: "Home" # - text: "Home"
icon: "fa-home" # icon: "fa-home"
href: "index.html" # href: "index.html"
- text: "How to" - text: "How to"
icon: "fa-question-circle" icon: "fa-question-circle"
menu: menu:
@ -100,9 +100,9 @@ navbar:
- text: "Work with WHONET Data" - text: "Work with WHONET Data"
icon: "fa-globe-americas" icon: "fa-globe-americas"
href: "articles/WHONET.html" href: "articles/WHONET.html"
- text: "Import Data From SPSS/SAS/Stata" # - text: "Import Data From SPSS/SAS/Stata"
icon: "fa-file-upload" # icon: "fa-file-upload"
href: "articles/SPSS.html" # href: "articles/SPSS.html"
- text: "Apply Eucast Rules" - text: "Apply Eucast Rules"
icon: "fa-exchange-alt" icon: "fa-exchange-alt"
href: "articles/EUCAST.html" href: "articles/EUCAST.html"
@ -115,16 +115,31 @@ navbar:
- text: "Get Properties of an Antiviral Drug" - text: "Get Properties of an Antiviral Drug"
icon: "fa-capsules" icon: "fa-capsules"
href: "reference/av_property.html" # reference instead of an article href: "reference/av_property.html" # reference instead of an article
- text: "With other pkgs"
icon: "fa-circles-overlap"
menu:
- text: "AMR & dplyr/tidyverse"
icon: "fa-circles-overlap"
href: "articles/other_pkg.html"
- text: "AMR & data.table"
icon: "fa-circles-overlap"
href: "articles/other_pkg.html"
- text: "AMR & tidymodels"
icon: "fa-circles-overlap"
href: "articles/other_pkg.html"
- text: "AMR & base R"
icon: "fa-circles-overlap"
href: "articles/other_pkg.html"
- text: "Manual" - text: "Manual"
icon: "fa-book-open" icon: "fa-book-open"
href: "reference/index.html" href: "reference/index.html"
- text: "Authors" - text: "Authors"
icon: "fa-users" icon: "fa-users"
href: "authors.html" href: "authors.html"
right:
- text: "Changelog" - text: "Changelog"
icon: "far fa-newspaper" icon: "far fa-newspaper"
href: "news/index.html" href: "news/index.html"
right:
- text: "Source Code" - text: "Source Code"
icon: "fab fa-github" icon: "fab fa-github"
href: "https://github.com/msberends/AMR" href: "https://github.com/msberends/AMR"

View File

@ -119,7 +119,7 @@ ab_atc_group1("AMX")
ab_atc_group2("AMX") ab_atc_group2("AMX")
ab_url("AMX") ab_url("AMX")
# smart lowercase tranformation # smart lowercase transformation
ab_name(x = c("AMC", "PLB")) ab_name(x = c("AMC", "PLB"))
ab_name(x = c("AMC", "PLB"), tolower = TRUE) ab_name(x = c("AMC", "PLB"), tolower = TRUE)

View File

@ -92,7 +92,7 @@ av_tradenames("ACI")
av_group("ACI") av_group("ACI")
av_url("ACI") av_url("ACI")
# smart lowercase tranformation # lowercase transformation
av_name(x = c("ACI", "VALA")) av_name(x = c("ACI", "VALA"))
av_name(x = c("ACI", "VALA"), tolower = TRUE) av_name(x = c("ACI", "VALA"), tolower = TRUE)

View File

@ -101,13 +101,13 @@ To work with R, probably the best option is to use [RStudio](https://www.rstudio
To import a data file, just click *Import Dataset* in the Environment tab: To import a data file, just click *Import Dataset* in the Environment tab:
![](https://github.com/msberends/AMR/raw/main/docs/import1.png) ![](https://msberends.github.io/AMR/import1.png)
If additional packages are needed, RStudio will ask you if they should be installed on beforehand. If additional packages are needed, RStudio will ask you if they should be installed on beforehand.
In the the window that opens, you can define all options (parameters) that should be used for import and you're ready to go: In the the window that opens, you can define all options (parameters) that should be used for import and you're ready to go:
![](https://github.com/msberends/AMR/raw/main/docs/import2.png) ![](https://msberends.github.io/AMR/import2.png)
If you want named variables to be imported as factors so it resembles SPSS more, use `as_factor()`. If you want named variables to be imported as factors so it resembles SPSS more, use `as_factor()`.

25
vignettes/other_pkg.Rmd Executable file
View File

@ -0,0 +1,25 @@
---
title: "Using AMR with other packages: AMR & dplyr/tidyverse"
output:
rmarkdown::html_vignette:
toc: true
toc_depth: 3
vignette: >
%\VignetteIndexEntry{How to conduct AMR data analysis}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
chunk_output_type: console
---
```{r setup, include = FALSE, results = 'markup'}
knitr::opts_chunk$set(
warning = FALSE,
collapse = TRUE,
comment = "#>",
fig.width = 7.5,
fig.height = 5
)
```
This page will be updated shortly, to give explicit examples of how to work ideally with the `AMR` package, for those who are used to working in `dplyr` or other tidyverse packages.