diff --git a/.Rbuildignore b/.Rbuildignore index ad2cea0a8..2a36087a2 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -30,6 +30,7 @@ ^vignettes/datasets\.Rmd$ ^vignettes/EUCAST\.Rmd$ ^vignettes/MDR\.Rmd$ +^vignettes/other_pkg.*\.Rmd$ ^vignettes/PCA\.Rmd$ ^vignettes/resistance_predict\.Rmd$ ^vignettes/SPSS\.Rmd$ diff --git a/.github/workflows/website.yaml b/.github/workflows/website.yaml index c128221ff..76755456a 100644 --- a/.github/workflows/website.yaml +++ b/.github/workflows/website.yaml @@ -65,7 +65,11 @@ jobs: - name: Set up R dependencies uses: r-lib/actions/setup-r-dependencies@v2 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 - name: Create website in separate branch diff --git a/DESCRIPTION b/DESCRIPTION index c9dff9545..881700da2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 2.0.0.9018 -Date: 2023-05-17 +Version: 2.0.0.9019 +Date: 2023-05-24 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NEWS.md b/NEWS.md index 0dd1195fb..f7b2bf3f2 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.0.0.9018 +# AMR 2.0.0.9019 ## Changed * 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 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()` +* Improved `as.mo()` algorithm for searching on only species names # AMR 2.0.0 diff --git a/R/ab_property.R b/R/ab_property.R index 205f5de03..fb5eba447 100755 --- a/R/ab_property.R +++ b/R/ab_property.R @@ -69,7 +69,7 @@ #' ab_atc_group2("AMX") #' ab_url("AMX") #' -#' # smart lowercase tranformation +#' # smart lowercase transformation #' ab_name(x = c("AMC", "PLB")) #' ab_name(x = c("AMC", "PLB"), tolower = TRUE) #' diff --git a/R/av_property.R b/R/av_property.R index e3e10f186..b3a8cb633 100755 --- a/R/av_property.R +++ b/R/av_property.R @@ -61,7 +61,7 @@ #' av_group("ACI") #' av_url("ACI") #' -#' # smart lowercase tranformation +#' # lowercase transformation #' av_name(x = c("ACI", "VALA")) #' av_name(x = c("ACI", "VALA"), tolower = TRUE) #' diff --git a/R/first_isolate.R b/R/first_isolate.R index 1283df015..5a4aae73b 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -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)) 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 } 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)) x$newvar_is_icu <- x[, col_icu, drop = TRUE] } else { - x$newvar_is_icu <- NA_real_ + x$newvar_is_icu <- NA } # method method <- coerce_method(method) diff --git a/R/mo.R b/R/mo.R index 345f4bbe7..bae76f106 100755 --- a/R/mo.R +++ b/R/mo.R @@ -281,9 +281,16 @@ as.mo <- function(x, 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) - 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 - 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) { first_chars <- paste0("(^| )", "[", paste(substr(x_parts, 1, 1), collapse = ""), "]") filtr <- which(AMR_env$MO_lookup$full_first %like_case% first_chars) diff --git a/R/sir.R b/R/sir.R index 06c07e2dc..aaafd029c 100755 --- a/R/sir.R +++ b/R/sir.R @@ -759,7 +759,7 @@ as_sir_method <- function(method_short, 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", "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 ) } diff --git a/_pkgdown.yml b/_pkgdown.yml index bc8e96429..14571e686 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -70,9 +70,9 @@ home: navbar: title: "AMR (for R)" left: - - text: "Home" - icon: "fa-home" - href: "index.html" + # - text: "Home" + # icon: "fa-home" + # href: "index.html" - text: "How to" icon: "fa-question-circle" menu: @@ -100,9 +100,9 @@ navbar: - text: "Work with WHONET Data" icon: "fa-globe-americas" href: "articles/WHONET.html" - - text: "Import Data From SPSS/SAS/Stata" - icon: "fa-file-upload" - href: "articles/SPSS.html" + # - text: "Import Data From SPSS/SAS/Stata" + # icon: "fa-file-upload" + # href: "articles/SPSS.html" - text: "Apply Eucast Rules" icon: "fa-exchange-alt" href: "articles/EUCAST.html" @@ -115,16 +115,31 @@ navbar: - text: "Get Properties of an Antiviral Drug" icon: "fa-capsules" 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" icon: "fa-book-open" href: "reference/index.html" - text: "Authors" icon: "fa-users" href: "authors.html" + right: - text: "Changelog" icon: "far fa-newspaper" href: "news/index.html" - right: - text: "Source Code" icon: "fab fa-github" href: "https://github.com/msberends/AMR" diff --git a/man/ab_property.Rd b/man/ab_property.Rd index 23c7525cb..00a0822de 100644 --- a/man/ab_property.Rd +++ b/man/ab_property.Rd @@ -119,7 +119,7 @@ ab_atc_group1("AMX") ab_atc_group2("AMX") ab_url("AMX") -# smart lowercase tranformation +# smart lowercase transformation ab_name(x = c("AMC", "PLB")) ab_name(x = c("AMC", "PLB"), tolower = TRUE) diff --git a/man/av_property.Rd b/man/av_property.Rd index bce3e163f..a644969d8 100644 --- a/man/av_property.Rd +++ b/man/av_property.Rd @@ -92,7 +92,7 @@ av_tradenames("ACI") av_group("ACI") av_url("ACI") -# smart lowercase tranformation +# lowercase transformation av_name(x = c("ACI", "VALA")) av_name(x = c("ACI", "VALA"), tolower = TRUE) diff --git a/vignettes/SPSS.Rmd b/vignettes/SPSS.Rmd.not similarity index 99% rename from vignettes/SPSS.Rmd rename to vignettes/SPSS.Rmd.not index f864bc083..dd51a0b46 100755 --- a/vignettes/SPSS.Rmd +++ b/vignettes/SPSS.Rmd.not @@ -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: -![](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. 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()`. diff --git a/vignettes/other_pkg.Rmd b/vignettes/other_pkg.Rmd new file mode 100755 index 000000000..53b3fba4b --- /dev/null +++ b/vignettes/other_pkg.Rmd @@ -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.