Browse Source

First CRAN submission edits

main v0.1.0
parent
commit
d8da8daf9a
No known key found for this signature in database
GPG Key ID: 904E4D816D2F58BA
  1. 11
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 3
      R/EUCAST.R
  4. 10
      R/atc.R
  5. 21
      R/classes.R
  6. 27
      R/first_isolates.R
  7. 13
      R/join.R
  8. 22
      R/rsi_analysis.R
  9. 42
      README.md
  10. 5
      man/EUCAST.Rd
  11. 1
      man/abname.Rd
  12. 12
      man/as.mic.Rd
  13. 10
      man/as.rsi.Rd
  14. 8
      man/atc_property.Rd
  15. 1
      man/first_isolate.Rd
  16. 14
      man/join.Rd
  17. 9
      man/key_antibiotics.Rd
  18. 24
      man/key_antibiotics_equal.Rd
  19. 21
      man/rsi.Rd
  20. 1
      man/rsi_predict.Rd

11
DESCRIPTION

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
Package: AMR
Version: 0.1.0
Date: 2018-02-20
Title: Antimicrobial Resistance (AMR) Analysis
Version: 0.1.1
Date: 2018-02-22
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(
given = c("Matthijs", "S."),
@ -19,8 +19,9 @@ Authors@R: c( @@ -19,8 +19,9 @@ Authors@R: c(
email = "e.hassing@certe.nl",
role = "ctb"))
Description: Functions to simplify the analysis of Antimicrobial Resistance (AMR)
of microbial isolates, by using new S3 classes and applying EUCAST expert rules
on antibiograms.
of microbial isolates, by using new S3 classes and applying EUCAST expert rules
on antibiograms according to Leclercq (2013)
<doi:10.1111/j.1469-0691.2011.03703.x>.
Depends: R (>= 3.0)
Imports: dplyr (>= 0.7.0), reshape2 (>= 1.4.0), xml2, rvest
URL: https://github.com/msberends/AMR

1
NAMESPACE

@ -21,7 +21,6 @@ export(interpretive_reading) @@ -21,7 +21,6 @@ export(interpretive_reading)
export(is.mic)
export(is.rsi)
export(key_antibiotics)
export(key_antibiotics_equal)
export(left_join_bactlist)
export(mo_property)
export(right_join_bactlist)

3
R/EUCAST.R

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
#' @rdname EUCAST
#' @export
#' @importFrom dplyr %>% left_join select
#' @return table with edited variables of antibiotics.
#' @source
#' EUCAST Expert Rules Version 2.0: \cr
#' Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility testing.} \emph{Clin Microbiol Infect.} 2013;19(2):141-60. \cr
@ -37,7 +38,7 @@ @@ -37,7 +38,7 @@
#' \url{http://www.eucast.org/expert_rules_and_intrinsic_resistance}
#' @examples
#' \dontrun{
#' tbl <- interpretive_reading(tbl)
#' tbl <- EUCAST_rules(tbl)
#' }
EUCAST_rules <- function(tbl,
col_bactcode = 'bacteriecode',

10
R/atc.R

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
#' Properties of an ATC code
#'
#' Gets data from the WHO to determine properties of an ATC of e.g. an antibiotic.
#' Gets data from the WHO to determine properties of an ATC of e.g. an antibiotic. \strong{This function requires an internet connection.}
#' @param atc_code a character or character vector with ATC code(s) of antibiotic(s)
#' @param property property of an ATC code. Valid values are \code{"ATC code"}, \code{"Name"}, \code{"DDD"}, \code{"U"} (\code{"unit"}), \code{"Adm.R"} en \code{"Note"}.
#' @param administration type of administration, see \emph{Details}
@ -54,6 +54,11 @@ @@ -54,6 +54,11 @@
#' @importFrom xml2 read_html
#' @importFrom rvest html_nodes html_table
#' @source \url{https://www.whocc.no/atc_ddd_alterations__cumulative/ddd_alterations/abbrevations/}
#' @examples
#' \donttest{
#' atc_property("J01CA04", "DDD", "O") # oral DDD of amoxicillin
#' atc_property("J01CA04", "DDD", "P") # parenteral DDD of amoxicillin
#' }
atc_property <- function(atc_code,
property,
administration = 'O',
@ -128,6 +133,7 @@ atc_property <- function(atc_code, @@ -128,6 +133,7 @@ atc_property <- function(atc_code,
#' @param textbetween text to put between multiple returned texts
#' @param tolower return output as lower case with function \code{\link{tolower}}.
#' @keywords ab antibiotics
#' @source \code{\link{ablist}}
#' @export
#' @importFrom dplyr %>% filter select slice
#' @examples
@ -148,8 +154,6 @@ atc_property <- function(atc_code, @@ -148,8 +154,6 @@ atc_property <- function(atc_code,
#'
#' abname("J01CR02", from = "atc", to = "umcg")
#' # "AMCL"
#'
#' @source \code{\link{ablist}}
abname <- function(abcode, from = 'umcg', to = 'official', textbetween = ' + ', tolower = FALSE) {
ablist <- AMR::ablist

21
R/classes.R

@ -26,8 +26,16 @@ @@ -26,8 +26,16 @@
#' @importFrom dplyr %>%
#' @examples
#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370)))
#'
#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370), "A", "B", "C"))
#' is.rsi(rsi_data)
#' plot(rsi_data)
#'
#' \donttest{
#' library(dplyr)
#' tbl %>%
#' mutate_at(vars(ends_with("_rsi")), as.rsi)
#' sapply(mic_data, is.rsi)
#' }
as.rsi <- function(x) {
if (is.rsi(x)) {
x
@ -157,6 +165,17 @@ plot.rsi <- function(x, ...) { @@ -157,6 +165,17 @@ plot.rsi <- function(x, ...) {
#' @return New class \code{mic}
#' @export
#' @importFrom dplyr %>%
#' @examples
#' mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))
#' is.mic(mic_data)
#' plot(mic_data)
#'
#' \donttest{
#' library(dplyr)
#' tbl %>%
#' mutate_at(vars(ends_with("_mic")), as.mic)
#' sapply(mic_data, is.mic)
#' }
as.mic <- function(x, na.rm = FALSE) {
if (is.mic(x)) {
x

27
R/first_isolates.R

@ -46,6 +46,7 @@ @@ -46,6 +46,7 @@
#' @examples
#' \dontrun{
#'
#' # set key antibiotics to a new variable
#' tbl$keyab <- key_antibiotics(tbl)
#'
#' tbl$first_isolate <-
@ -355,7 +356,13 @@ first_isolate <- function(tbl, @@ -355,7 +356,13 @@ first_isolate <- function(tbl,
#' @param amcl,amox,cfot,cfta,cftr,cfur,cipr,clar,clin,clox,doxy,gent,line,mero,peni,pita,rifa,teic,trsu,vanc column names of antibiotics.
#' @export
#' @importFrom dplyr %>% mutate if_else
#' @return Character of length 1.
#' @seealso \code{\link{mo_property}} \code{\link{ablist}}
#' @examples
#' \donttest{
#' #' # set key antibiotics to a new variable
#' tbl$keyab <- key_antibiotics(tbl)
#' }
key_antibiotics <- function(tbl,
col_bactcode = 'bacteriecode',
info = TRUE,
@ -439,15 +446,17 @@ key_antibiotics <- function(tbl, @@ -439,15 +446,17 @@ key_antibiotics <- function(tbl,
}
#' Compare key antibiotics
#'
#' Check whether two text values with key antibiotics match. Supports vectors.
#' @param x,y tekst (or multiple text vectors) with antimicrobial interpretations
#' @param ignore_I ignore \code{"I"} as antimicrobial interpretation of key antibiotics (with \code{FALSE}, changes in antibiograms from S to I and I to R will be interpreted as difference)
#' @param info print progress
#' @return logical
#' @export
#' @seealso \code{\link{key_antibiotics}}
# Compare key antibiotics
#
# Check whether two text values with key antibiotics match. Supports vectors.
# @param x,y tekst (or multiple text vectors) with antimicrobial interpretations
# @param ignore_I ignore \code{"I"} as antimicrobial interpretation of key antibiotics (with \code{FALSE}, changes in antibiograms from S to I and I to R will be interpreted as difference)
# @param info print progress
# @return logical
# @export
# @seealso \code{\link{key_antibiotics}}
# only internal use
key_antibiotics_equal <- function(x, y, ignore_I = TRUE, info = FALSE) {
if (length(x) != length(y)) {
stop('Length of `x` and `y` must be equal.')

13
R/join.R

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#' Join van tabel en \code{bactlist}
#' Join a table with \code{bactlist}
#'
#' Join the list of microorganisms \code{\link{bactlist}} easily to an existing table.
#' @rdname join
@ -9,6 +9,17 @@ @@ -9,6 +9,17 @@
#' @param ... other parameters to pass trhough to \code{dplyr::\link[dplyr]{join}}.
#' @details As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information.
#' @export
#' @examples
#' df <- data.frame(date = seq(from = as.Date("2018-01-01"),
#' to = as.Date("2018-01-07"),
#' by = 1),
#' bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR",
#' "ESCCOL", "ESCCOL", "ESCCOL"),
#' stringsAsFactors = FALSE)
#'
#' colnames(df)
#' df2 <- left_join_bactlist(df, "bacteria_id")
#' colnames(df2)
inner_join_bactlist <- function(x, by = 'bactid', ...) {
# no name set to `by` parameter
if (is.null(names(by))) {

22
R/rsi_analysis.R

@ -167,7 +167,7 @@ rsi_df <- function(tbl, @@ -167,7 +167,7 @@ rsi_df <- function(tbl,
#' Resistance of isolates
#'
#' This function can be used in \code{\link[dplyr]{summarise}}, see \emph{Examples}. CaBerekent het percentage S, SI, I, IR of R van een lijst isolaten.
#' This function can be used in \code{dplyr}s \code{\link[dplyr]{summarise}}, see \emph{Examples}. Calculate the percentage S, SI, I, IR or R of a vector of isolates.
#' @param ab1,ab2 list with interpretations of an antibiotic
#' @inheritParams rsi_df
#' @details This function uses the \code{\link{rsi_df}} function internally.
@ -177,20 +177,19 @@ rsi_df <- function(tbl, @@ -177,20 +177,19 @@ rsi_df <- function(tbl,
#' @examples
#' \dontrun{
#' tbl %>%
#' group_by(hospital) %>%
#' summarise(cipr = rsi(cipr))
#'
#' tbl %>%
#' group_by(year, hospital) %>%
#' summarise(
#' isolates = n(),
#' cipro = rsi(cipr, percent = TRUE),
#' amoxi = rsi(amox, percent = TRUE)
#' )
#'
#' tbl %>%
#' group_by(hospital) %>%
#' summarise(cipr = rsi(cipr))
#' cipro = rsi(cipr %>% as.rsi(), percent = TRUE),
#' amoxi = rsi(amox %>% as.rsi(), percent = TRUE))
#'
#' rsi(as.rsi(isolates$amox))
#'
#' rsi(isolates$amox)
#'
#' rsi(isolates$amcl, interpretation = "S")
#' rsi(as.rsi(isolates$amcl), interpretation = "S")
#' }
rsi <- function(ab1, ab2 = NA, interpretation = 'IR', minimum = 30, percent = FALSE, info = FALSE, warning = FALSE) {
functietekst <- as.character(match.call())
@ -258,6 +257,7 @@ rsi <- function(ab1, ab2 = NA, interpretation = 'IR', minimum = 30, percent = FA @@ -258,6 +257,7 @@ rsi <- function(ab1, ab2 = NA, interpretation = 'IR', minimum = 30, percent = FA
#' rsi_predict(tbl[which(first_isolate == TRUE & genus == "Haemophilus"),], "amcl")
#'
#' # or with dplyr so you can actually read it:
#' library(dplyr)
#' tbl %>%
#' filter(first_isolate == TRUE,
#' genus == "Haemophilus") %>%

42
README.md

@ -12,6 +12,26 @@ AMR can also be predicted for the forthcoming years with the `rsi_predict` funct @@ -12,6 +12,26 @@ AMR can also be predicted for the forthcoming years with the `rsi_predict` funct
It also contains functions to translate antibiotic codes from the lab (like `"AMOX"`) or the [WHO](https://www.whocc.no/atc_ddd_index/?code=J01CA04&showdescription=no) (like `"J01CA04"`) to trivial names (like `"amoxicillin"`) and vice versa.
## How to get it?
[![CRAN_Badge](http://www.r-pkg.org/badges/version/AMR)](http://cran.r-project.org/package=AMR)
This package is available on CRAN (latest stable version) and also here on GitHub (latest development version).
#### Latest stable version from CRAN (recommended)
RStudio:
- Click on `Tools` and then `Install Packages..`
- Type in `AMR` and press <kbd>Install</kbd>
Other:
```r
install.packages("AMR")
```
#### Latest development version from GitHub
```r
devtools::install_github("msberends/AMR")
```
## How to use it?
```r
# Call it with:
@ -95,28 +115,6 @@ abname(...) @@ -95,28 +115,6 @@ abname(...)
abname("J01CR02", from = "atc", to = "umcg") # "AMCL"
```
## How to get it?
This package is only available here on GitHub, but respects the [CRAN Repository Policy](https://cran.r-project.org/web/packages/policies.html).
*Installation commands:*
```r
library(devtools)
install_github("msberends/AMR")
```
*Working behind a proxy? Then use:*
```r
library(httr)
library(devtools)
set_config(use_proxy("yourproxydomain.com",
8080,
"username",
"password",
"any")) # change "any" to "basic" or "digest" if needed
install_github("msberends/AMR")
reset_config()
```
## Authors
- [Berends MS](https://github.com/msberends)<sup>1,2</sup>, PhD Student

5
man/EUCAST.Rd

@ -44,11 +44,14 @@ interpretive_reading(...) @@ -44,11 +44,14 @@ interpretive_reading(...)
\item{...}{parameters that are passed on to \code{EUCAST_rules}}
}
\value{
table with edited variables of antibiotics.
}
\description{
Apply expert rules (like intrinsic resistance), as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, \url{http://eucast.org}), see \emph{Source}.
}
\examples{
\dontrun{
tbl <- interpretive_reading(tbl)
tbl <- EUCAST_rules(tbl)
}
}

1
man/abname.Rd

@ -40,7 +40,6 @@ abname("AMCL", to = "atc") @@ -40,7 +40,6 @@ abname("AMCL", to = "atc")
abname("J01CR02", from = "atc", to = "umcg")
# "AMCL"
}
\keyword{ab}
\keyword{antibiotics}

12
man/as.mic.Rd

@ -20,3 +20,15 @@ New class \code{mic} @@ -20,3 +20,15 @@ New class \code{mic}
\description{
This transforms a vector to a new class\code{mic}, which is an ordered factor valid MIC values as levels. Invalid MIC values will be translated as \code{NA} with a warning.
}
\examples{
mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))
is.mic(mic_data)
plot(mic_data)
\donttest{
library(dplyr)
tbl \%>\%
mutate_at(vars(ends_with("_mic")), as.mic)
sapply(mic_data, is.mic)
}
}

10
man/as.rsi.Rd

@ -20,6 +20,14 @@ This transforms a vector to a new class \code{rsi}, which is an ordered factor w @@ -20,6 +20,14 @@ This transforms a vector to a new class \code{rsi}, which is an ordered factor w
}
\examples{
rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370)))
rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370), "A", "B", "C"))
is.rsi(rsi_data)
plot(rsi_data)
\donttest{
library(dplyr)
tbl \%>\%
mutate_at(vars(ends_with("_rsi")), as.rsi)
sapply(mic_data, is.rsi)
}
}

8
man/atc_property.Rd

@ -20,7 +20,7 @@ atc_property(atc_code, property, administration = "O", @@ -20,7 +20,7 @@ atc_property(atc_code, property, administration = "O",
\item{url}{url of website of the WHO. The sign \code{\%s} can be used as a placeholder for ATC codes.}
}
\description{
Gets data from the WHO to determine properties of an ATC of e.g. an antibiotic.
Gets data from the WHO to determine properties of an ATC of e.g. an antibiotic. \strong{This function requires an internet connection.}
}
\details{
Abbreviations for the property \code{"Adm.R"} (parameter \code{administration}):
@ -49,3 +49,9 @@ Abbreviations for the property \code{"U"} (unit): @@ -49,3 +49,9 @@ Abbreviations for the property \code{"U"} (unit):
\item{\code{"ml"}}{ = milliliter (e.g. eyedrops)}
}
}
\examples{
\donttest{
atc_property("J01CA04", "DDD", "O") # oral DDD of amoxicillin
atc_property("J01CA04", "DDD", "P") # parenteral DDD of amoxicillin
}
}

1
man/first_isolate.Rd

@ -57,6 +57,7 @@ To conduct an analysis of antimicrobial resistance, you should only include the @@ -57,6 +57,7 @@ To conduct an analysis of antimicrobial resistance, you should only include the
\examples{
\dontrun{
# set key antibiotics to a new variable
tbl$keyab <- key_antibiotics(tbl)
tbl$first_isolate <-

14
man/join.Rd

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
\alias{full_join_bactlist}
\alias{semi_join_bactlist}
\alias{anti_join_bactlist}
\title{Join van tabel en \code{bactlist}}
\title{Join a table with \code{bactlist}}
\usage{
inner_join_bactlist(x, by = "bactid", ...)
@ -36,3 +36,15 @@ Join the list of microorganisms \code{\link{bactlist}} easily to an existing tab @@ -36,3 +36,15 @@ Join the list of microorganisms \code{\link{bactlist}} easily to an existing tab
\details{
As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information.
}
\examples{
df <- data.frame(date = seq(from = as.Date("2018-01-01"),
to = as.Date("2018-01-07"),
by = 1),
bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR",
"ESCCOL", "ESCCOL", "ESCCOL"),
stringsAsFactors = FALSE)
colnames(df)
df2 <- left_join_bactlist(df, "bacteria_id")
colnames(df2)
}

9
man/key_antibiotics.Rd

@ -20,9 +20,18 @@ key_antibiotics(tbl, col_bactcode = "bacteriecode", info = TRUE, @@ -20,9 +20,18 @@ key_antibiotics(tbl, col_bactcode = "bacteriecode", info = TRUE,
\item{amcl, amox, cfot, cfta, cftr, cfur, cipr, clar, clin, clox, doxy, gent, line, mero, peni, pita, rifa, teic, trsu, vanc}{column names of antibiotics.}
}
\value{
Character of length 1.
}
\description{
Key antibiotics based on bacteria ID
}
\examples{
\donttest{
#' # set key antibiotics to a new variable
tbl$keyab <- key_antibiotics(tbl)
}
}
\seealso{
\code{\link{mo_property}} \code{\link{ablist}}
}

24
man/key_antibiotics_equal.Rd

@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/first_isolates.R
\name{key_antibiotics_equal}
\alias{key_antibiotics_equal}
\title{Compare key antibiotics}
\usage{
key_antibiotics_equal(x, y, ignore_I = TRUE, info = FALSE)
}
\arguments{
\item{x, y}{tekst (or multiple text vectors) with antimicrobial interpretations}
\item{ignore_I}{ignore \code{"I"} as antimicrobial interpretation of key antibiotics (with \code{FALSE}, changes in antibiograms from S to I and I to R will be interpreted as difference)}
\item{info}{print progress}
}
\value{
logical
}
\description{
Check whether two text values with key antibiotics match. Supports vectors.
}
\seealso{
\code{\link{key_antibiotics}}
}

21
man/rsi.Rd

@ -24,28 +24,27 @@ rsi(ab1, ab2 = NA, interpretation = "IR", minimum = 30, percent = FALSE, @@ -24,28 +24,27 @@ rsi(ab1, ab2 = NA, interpretation = "IR", minimum = 30, percent = FALSE,
Double or, when \code{percent = TRUE}, a character.
}
\description{
This function can be used in \code{\link[dplyr]{summarise}}, see \emph{Examples}. CaBerekent het percentage S, SI, I, IR of R van een lijst isolaten.
This function can be used in \code{dplyr}s \code{\link[dplyr]{summarise}}, see \emph{Examples}. Calculate the percentage S, SI, I, IR or R of a vector of isolates.
}
\details{
This function uses the \code{\link{rsi_df}} function internally.
}
\examples{
\dontrun{
tbl \%>\%
group_by(hospital) \%>\%
summarise(cipr = rsi(cipr))
tbl \%>\%
group_by(year, hospital) \%>\%
summarise(
isolates = n(),
cipro = rsi(cipr, percent = TRUE),
amoxi = rsi(amox, percent = TRUE)
)
tbl \%>\%
group_by(hospital) \%>\%
summarise(cipr = rsi(cipr))
rsi(isolates$amox)
cipro = rsi(cipr \%>\% as.rsi(), percent = TRUE),
amoxi = rsi(amox \%>\% as.rsi(), percent = TRUE))
rsi(as.rsi(isolates$amox))
rsi(isolates$amcl, interpretation = "S")
rsi(as.rsi(isolates$amcl), interpretation = "S")
}
}
\keyword{antibiotics}

1
man/rsi_predict.Rd

@ -40,6 +40,7 @@ Create a prediction model to predict antimicrobial resistance for the next years @@ -40,6 +40,7 @@ Create a prediction model to predict antimicrobial resistance for the next years
rsi_predict(tbl[which(first_isolate == TRUE & genus == "Haemophilus"),], "amcl")
# or with dplyr so you can actually read it:
library(dplyr)
tbl \%>\%
filter(first_isolate == TRUE,
genus == "Haemophilus") \%>\%

Loading…
Cancel
Save