1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 11:51:59 +02:00

First CRAN submission edits

This commit is contained in:
2018-02-22 20:48:48 +01:00
parent 77194527b5
commit d8da8daf9a
20 changed files with 162 additions and 94 deletions

View File

@ -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 @@
#' \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
View File

@ -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 @@
#' @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,
#' @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,
#'
#' abname("J01CR02", from = "atc", to = "umcg")
#' # "AMCL"
#'
#' @source \code{\link{ablist}}
abname <- function(abcode, from = 'umcg', to = 'official', textbetween = ' + ', tolower = FALSE) {
ablist <- AMR::ablist

View File

@ -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, ...) {
#' @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

View File

@ -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,
#' @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,
}
#' 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.')

View File

@ -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 @@
#' @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))) {

View File

@ -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,
#' @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)
#' )
#' cipro = rsi(cipr %>% as.rsi(), percent = TRUE),
#' amoxi = rsi(amox %>% as.rsi(), percent = TRUE))
#'
#' rsi(as.rsi(isolates$amox))
#'
#' tbl %>%
#' group_by(hospital) %>%
#' summarise(cipr = rsi(cipr))
#'
#' 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
#' 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") %>%