From 7c667eb732cf21b46f857a0b058db34e99121df2 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Wed, 1 Aug 2018 08:03:31 +0200 Subject: [PATCH] emph guess_bactid --- .travis.yml | 1 - NEWS.md | 2 +- R/bactid.R | 26 +++++++++++--------------- README.md | 4 ++-- man/as.bactid.Rd | 9 +++++---- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03445b63..27136ca9 100755 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,6 @@ jobs: matrix: allow_failures: - r: 3.1 - - r: 3.2 - r: devel r_packages: covr cache: packages diff --git a/NEWS.md b/NEWS.md index faabe1af..804d8d91 100755 --- a/NEWS.md +++ b/NEWS.md @@ -7,7 +7,7 @@ * Universal: amoxicillin, amoxicillin/clavlanic acid, cefuroxime, piperacillin/tazobactam, ciprofloxacin, trimethoprim/sulfamethoxazole * Gram-positive: vancomycin, teicoplanin, tetracycline, erythromycin, oxacillin, rifampicin * Gram-negative: gentamicin, tobramycin, colistin, cefotaxime, ceftazidime, meropenem -* Functions `as.bactid` and `is.bactid` to transform/look up microbial ID's; this replaces the function `guess_bactid` but it will remain available for backwards compatibility +* Functions `as.bactid` and `is.bactid` to transform/look up microbial ID's * For convience, new descriptive statistical functions `kurtosis` and `skewness` that are lacking in base R - they are generic functions and have support for vectors, data.frames and matrices * Function `g.test` to perform the Χ2 distributed [*G*-test](https://en.wikipedia.org/wiki/G-test), which use is the same as `chisq.test` * Function `ratio` to transform a vector of values to a preset ratio diff --git a/R/bactid.R b/R/bactid.R index ba677b59..75ed14eb 100644 --- a/R/bactid.R +++ b/R/bactid.R @@ -21,7 +21,9 @@ #' Use this function to determine a valid ID based on a genus (and species). This input can be a full name (like \code{"Staphylococcus aureus"}), an abbreviated name (like \code{"S. aureus"}), or just a genus. You could also \code{\link{select}} a genus and species column, zie Examples. #' @param x a character vector or a dataframe with one or two columns #' @rdname as.bactid -#' @details Some exceptions have been built in to get more logical results, based on prevalence of human pathogens. For example: +#' @details \code{guess_bactid} does exactly the same as \code{as.bactid}. +#' +#' Some exceptions have been built in to get more logical results, based on prevalence of human pathogens. For example: #' \itemize{ #' \item{\code{"E. coli"} will return the ID of \emph{Escherichia coli} and not \emph{Entamoeba coli}, although the latter would alphabetically come first} #' \item{\code{"H. influenzae"} will return the ID of \emph{Haemophilus influenzae} and not \emph{Haematobacter influenzae}} @@ -53,17 +55,16 @@ #' library(dplyr) #' df$bactid <- df %>% #' select(microorganism_name) %>% -#' as.bactid() +#' guess_bactid() #' #' # and can even contain 2 columns, which is convenient for genus/species combinations: #' df$bactid <- df %>% #' select(genus, species) %>% -#' as.bactid() +#' guess_bactid() #' #' # same result: #' df <- df %>% -#' mutate(bactid = paste(genus, species) %>% -#' as.bactid()) +#' mutate(bactid = guess_bactid(paste(genus, species))) #' } as.bactid <- function(x) { @@ -158,7 +159,8 @@ as.bactid <- function(x) { next } if (toupper(x.backup[i]) == 'MRSE') { - x[i] <- 'Staphylococcus epidermidis' + x[i] <- 'STAEPI' + next } if (toupper(x.backup[i]) == 'VRE') { x[i] <- 'ENC' @@ -169,15 +171,9 @@ as.bactid <- function(x) { x[i] <- 'PSEAER' next } - if (toupper(x.backup[i]) == 'PISP' - | toupper(x.backup[i]) == 'PRSP') { - # peni resistant S. pneumoniae - x[i] <- 'Streptococcus pneumoniae' - } - if (toupper(x.backup[i]) == 'VISP' - | toupper(x.backup[i]) == 'VRSP') { - # vanco resistant S. pneumoniae - x[i] <- 'Streptococcus pneumoniae' + if (toupper(x.backup[i]) %in% c('PISP', 'PRSP', 'VISP', 'VRSP')) { + # peni R, peni I, vanco I, vanco R: S. pneumoniae + x[i] <- 'STCPNE' } } diff --git a/README.md b/README.md index 1f147965..805465f6 100755 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ The functions to calculate microbial resistance use expressions that are not eva This package [is published on CRAN](http://cran.r-project.org/package=AMR), the official R network. ### Install from CRAN (recommended) -[![CRAN_Badge](https://img.shields.io/cran/v/AMR.svg?label=CRAN)](http://cran.r-project.org/package=AMR) [![CRAN_Downloads](https://cranlogs.r-pkg.org/badges/grand-total/AMR)](http://cran.r-project.org/package=AMR) +[![CRAN_Badge](https://img.shields.io/cran/v/AMR.svg?label=CRAN&colorB=3679BC)](http://cran.r-project.org/package=AMR) [![CRAN_Downloads](https://cranlogs.r-pkg.org/badges/grand-total/AMR)](http://cran.r-project.org/package=AMR) -(Note: downloads measured only by [cran.rstudio.com](https://cran.rstudio.com/package=AMR), i.e. this excludes the official [cran.r-project.org](https://cran.r-project.org/package=AMR)) +(Note: Downloads measured only by [cran.rstudio.com](https://cran.rstudio.com/package=AMR), this excludes e.g. the official [cran.r-project.org](https://cran.r-project.org/package=AMR)) - RStudio favicon Install using [RStudio](http://www.rstudio.com) (recommended): - Click on `Tools` and then `Install Packages...` diff --git a/man/as.bactid.Rd b/man/as.bactid.Rd index 3a17bc6a..ebd58f68 100644 --- a/man/as.bactid.Rd +++ b/man/as.bactid.Rd @@ -22,6 +22,8 @@ Character (vector) with class \code{"bactid"}. Unknown values will return \code{ Use this function to determine a valid ID based on a genus (and species). This input can be a full name (like \code{"Staphylococcus aureus"}), an abbreviated name (like \code{"S. aureus"}), or just a genus. You could also \code{\link{select}} a genus and species column, zie Examples. } \details{ +\code{guess_bactid} does exactly the same as \code{as.bactid}. + Some exceptions have been built in to get more logical results, based on prevalence of human pathogens. For example: \itemize{ \item{\code{"E. coli"} will return the ID of \emph{Escherichia coli} and not \emph{Entamoeba coli}, although the latter would alphabetically come first} @@ -51,17 +53,16 @@ df$bactid <- as.bactid(df$microorganism_name) library(dplyr) df$bactid <- df \%>\% select(microorganism_name) \%>\% - as.bactid() + guess_bactid() # and can even contain 2 columns, which is convenient for genus/species combinations: df$bactid <- df \%>\% select(genus, species) \%>\% - as.bactid() + guess_bactid() # same result: df <- df \%>\% - mutate(bactid = paste(genus, species) \%>\% - as.bactid()) + mutate(bactid = guess_bactid(paste(genus, species))) } } \seealso{