diff --git a/.Rbuildignore b/.Rbuildignore index 45a4d842..0496b081 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -21,7 +21,7 @@ ^pkgdown$ ^public$ ^data-raw$ -R/aa_test.R$ ^\.lintr$ ^vignettes/benchmark.* ^vignettes/SPSS.* +^tests/appveyor$ diff --git a/DESCRIPTION b/DESCRIPTION index d4dbd964..7de38f74 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.8.0.9016 -Date: 2019-11-05 +Version: 0.8.0.9017 +Date: 2019-11-06 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index cfca1ca2..8c1bcb95 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 0.8.0.9016 -Last updated: 05-Nov-2019 +# AMR 0.8.0.9017 +Last updated: 06-Nov-2019 ### New * Support for a new MDRO guideline: Magiorakos AP, Srinivasan A *et al.* "Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance." Clinical Microbiology and Infection (2012). diff --git a/R/ab.R b/R/ab.R index e682e242..ec6bf1de 100755 --- a/R/ab.R +++ b/R/ab.R @@ -25,7 +25,6 @@ #' @param x character vector to determine to antibiotic ID #' @param ... arguments passed on to internal functions #' @rdname as.ab -#' @keywords atc #' @inheritSection WHOCC WHOCC #' @export #' @importFrom dplyr %>% filter slice pull diff --git a/R/ab_property.R b/R/ab_property.R index 50cbaf50..5f6cf662 100644 --- a/R/ab_property.R +++ b/R/ab_property.R @@ -83,6 +83,7 @@ ab_name <- function(x, language = get_locale(), tolower = FALSE, ...) { } #' @rdname ab_property +#' @aliases ATC #' @export ab_atc <- function(x, ...) { ab_validate(x = x, property = "atc", ...) diff --git a/R/age.R b/R/age.R index 55b00135..c6b301bd 100755 --- a/R/age.R +++ b/R/age.R @@ -106,7 +106,6 @@ age <- function(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE) { #' \item{\code{"tens"}, equivalent of: \code{1:10 * 10}. This will split on 0-9, 10-19, 20-29, ... 80-89, 90-99, 100+.} #' } #' } -#' @keywords age_group age #' @return Ordered \code{\link{factor}} #' @seealso To determine ages, based on one or more reference dates, use the \code{\link{age}} function. #' @export diff --git a/R/count.R b/R/count.R index 00c794ac..8d6b0ff1 100755 --- a/R/count.R +++ b/R/count.R @@ -37,7 +37,6 @@ #' @inheritSection portion Combination therapy #' @source Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html} #' @seealso \code{\link{portion}_*} to calculate microbial resistance and susceptibility. -#' @keywords resistance susceptibility rsi antibiotics isolate isolates #' @return Integer #' @rdname count #' @name count diff --git a/R/disk.R b/R/disk.R index 42689644..264dfba1 100644 --- a/R/disk.R +++ b/R/disk.R @@ -27,7 +27,7 @@ #' @param na.rm a logical indicating whether missing values should be removed #' @details Interpret disk values as RSI values with \code{\link{as.rsi}}. It supports guidelines from EUCAST and CLSI. #' @return Ordered integer factor with new class \code{disk} -#' @keywords disk +#' @aliases disk #' @export #' @seealso \code{\link{as.rsi}} #' @inheritSection AMR Read more on our website! diff --git a/R/eucast_rules.R b/R/eucast_rules.R index e1daabc6..472209e3 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -122,7 +122,7 @@ EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016" #' \strong{TMP}: trimethoprim (\href{https://www.whocc.no/atc_ddd_index/?code=J01EA01}{J01EA01}), #' \strong{SXT}: trimethoprim/sulfamethoxazole (\href{https://www.whocc.no/atc_ddd_index/?code=J01EE01}{J01EE01}), #' \strong{VAN}: vancomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XA01}{J01XA01}). -#' @keywords interpretive eucast reading resistance +#' @aliases EUCAST #' @rdname eucast_rules #' @export #' @importFrom dplyr %>% select pull mutate_at vars group_by summarise n diff --git a/R/filter_ab_class.R b/R/filter_ab_class.R index 6b3bfd88..1ab7f9a1 100644 --- a/R/filter_ab_class.R +++ b/R/filter_ab_class.R @@ -29,7 +29,6 @@ #' @param ... parameters passed on to \code{filter_at} from the \code{dplyr} package #' @details The \code{group} column in \code{\link{antibiotics}} data set will be searched for \code{ab_class} (case-insensitive). If no results are found, the \code{atc_group1} and \code{atc_group2} columns will be searched. Next, \code{x} will be checked for column names with a value in any abbreviations, codes or official names found in the \code{antibiotics} data set. #' @rdname filter_ab_class -#' @keywords filter fillter_class #' @importFrom dplyr filter_at %>% select vars any_vars all_vars #' @importFrom crayon bold blue #' @export diff --git a/R/first_isolate.R b/R/first_isolate.R index fc9c24af..95dafc14 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -70,7 +70,6 @@ #' \strong{2. Using} \code{type = "points"} \strong{and parameter} \code{points_threshold} \cr #' A difference from I to S|R (or vice versa) means 0.5 points, a difference from S to R (or vice versa) means 1 point. When the sum of points exceeds \code{points_threshold}, which default to \code{2}, an isolate will be (re)selected as a first weighted isolate. #' @rdname first_isolate -#' @keywords isolate isolates first #' @seealso \code{\link{key_antibiotics}} #' @export #' @importFrom dplyr arrange_at lag between row_number filter mutate arrange pull ungroup diff --git a/R/g.test.R b/R/g.test.R index adf6db01..5ccad116 100755 --- a/R/g.test.R +++ b/R/g.test.R @@ -61,7 +61,6 @@ #' where \code{df} are the degrees of freedom. #' #' If there are more than two categories and you want to find out which ones are significantly different from their null expectation, you can use the same method of testing each category vs. the sum of all categories, with the Bonferroni correction. You use \emph{G}-tests for each category, of course. -#' @keywords chi #' @seealso \code{\link{chisq.test}} #' @references [1] McDonald, J.H. 2014. \strong{Handbook of Biological Statistics (3rd ed.)}. Sparky House Publishing, Baltimore, Maryland. \url{http://www.biostathandbook.com/gtestgof.html}. #' @source This code is almost identical to \code{\link{chisq.test}}, except that: diff --git a/R/like.R b/R/like.R index 6b388e12..9ba97a2e 100755 --- a/R/like.R +++ b/R/like.R @@ -49,9 +49,8 @@ #' # get frequencies of bacteria whose name start with 'Ent' or 'ent' #' library(dplyr) #' example_isolates %>% -#' left_join_microorganisms() %>% -#' filter(genus %like% '^ent') %>% -#' freq(genus, species) +#' filter(mo_genus(mo) %like% '^ent') %>% +#' freq(mo_fullname(mo)) like <- function(x, pattern, ignore.case = TRUE) { if (length(pattern) > 1) { if (length(x) != length(pattern)) { diff --git a/R/mdro.R b/R/mdro.R index 3ae7752d..20028752 100755 --- a/R/mdro.R +++ b/R/mdro.R @@ -26,6 +26,7 @@ #' @param info print progress #' @inheritParams eucast_rules #' @param pct_required_classes minimal required percentage of antimicrobial classes that must be available per isolate, rounded down. For example, with the default guideline, 17 antimicrobial classes must be available for \emph{S. aureus}. Setting this \code{pct_required_classes} argument to \code{0.5} (default) means that for every \emph{S. aureus} isolate at least 8 different classes must be available. Any lower number of available classes will return \code{NA} for that isolate. +#' @param combine_SI a logical to indicate whether all values of S and I must be merged into one, so resistance is only considered when isolates are R, not I. As this is the default behaviour of the \code{mdro()} function, it follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. When using \code{combine_SI = FALSE}, resistance is considered when isolates are R or I. #' @param verbose a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not. #' @inheritSection eucast_rules Antibiotics #' @details @@ -43,7 +44,7 @@ #' Please suggest your own (country-specific) guidelines by letting us know: \url{https://gitlab.com/msberends/AMR/issues/new}. #' #' \strong{Note:} Every test that involves the Enterobacteriaceae family, will internally be performed using its newly named order Enterobacterales, since the Enterobacteriaceae family has been taxonomically reclassified by Adeolu \emph{et al.} in 2016. Before that, Enterobacteriaceae was the only family under the Enterobacteriales (with an i) order. All species under the old Enterobacteriaceae family are still under the new Enterobacterales (without an i) order, but divided into multiple families. The way tests are performed now by this \code{mdro()} function makes sure that results from before 2016 and after 2016 are identical. -#' +#' @inheritSection as.rsi Interpretation of S, I and R #' @return \itemize{ #' \item{CMI 2012 paper - function \code{mdr_cmi2012()} or \code{mdro()}:\cr Ordered factor with levels \code{Negative < Multi-drug-resistant (MDR) < Extensively drug-resistant (XDR) < Pandrug-resistant (PDR)}} #' \item{TB guideline - function \code{mdr_tb()} or \code{mdro(..., guideline = "TB")}:\cr Ordered factor with levels \code{Negative < Mono-resistant < Poly-resistant < Multi-drug-resistant < Extensively drug-resistant}} @@ -51,6 +52,7 @@ #' \item{Everything else:\cr Ordered factor with levels \code{Negative < Positive, unconfirmed < Positive}. The value \code{"Positive, unconfirmed"} means that, according to the guideline, it is not entirely sure if the isolate is multi-drug resistant and this should be confirmed with additional (e.g. molecular) tests} #' } #' @rdname mdro +#' @aliases MDR XDR PDR BRMO 3MRGN 4MRGN #' @importFrom dplyr %>% filter_at vars all_vars pull mutate_at #' @importFrom crayon blue bold italic #' @importFrom cleaner percentage @@ -80,8 +82,9 @@ mdro <- function(x, guideline = NULL, col_mo = NULL, info = TRUE, - verbose = FALSE, pct_required_classes = 0.5, + combine_SI = TRUE, + verbose = FALSE, ...) { if (verbose == TRUE & interactive()) { @@ -109,7 +112,7 @@ mdro <- function(x, # allow pct_required_classes = 75 -> pct_required_classes = 0.75 pct_required_classes <- pct_required_classes / 100 } - + if (!is.null(list(...)$country)) { warning("Using `country` is deprecated, use `guideline` instead. Please see ?mdro.", call. = FALSE) guideline <- list(...)$country @@ -410,8 +413,19 @@ mdro <- function(x, if (guideline$code == "tb" & length(abx_tb) == 0) { stop("No antimycobacterials found in data set.", call. = FALSE) } + + if (combine_SI == TRUE) { + search_result <- "R" + } else { + search_result <- c("R", "I") + } if (info == TRUE) { + if (combine_SI == TRUE) { + cat("\nOnly results with 'R' are considered as resistance. Use `combine_SI = FALSE` to also consider 'I' as resistance.\n") + } else { + cat("\nResults with 'R' or 'I' are considered as resistance. Use `combine_SI = TRUE` to only consider 'R' as resistance.\n") + } cat("\nDetermining multidrug-resistant organisms (MDRO), according to:\n", bold("Guideline: "), italic(guideline$name), "\n", bold("Version: "), guideline$version, "\n", @@ -444,19 +458,21 @@ mdro <- function(x, x <<- x %>% mutate_at(vars(cols), as.rsi) x[rows, "columns_nonsusceptible"] <<- sapply(rows, function(row, group_vct = cols) { - cols_nonsus <- sapply(x[row, group_vct, drop = FALSE], function(y) y == "R") + cols_nonsus <- sapply(x[row, group_vct, drop = FALSE], + function(y) y %in% search_result) paste(sort(c(unlist(strsplit(x[row, "columns_nonsusceptible", drop = TRUE], ", ")), names(cols_nonsus)[cols_nonsus])), collapse = ", ") }) + if (any_all == "any") { - row_filter <- which(x[, cols] == "R") + search_function <- dplyr::any_vars } else if (any_all == "all") { - row_filter <- x %>% - mutate(index = seq_len(nrow(.))) %>% - filter_at(vars(cols), all_vars(. == "R")) %>% - pull((index)) + search_function <- dplyr::all_vars } + row_filter <- x %>% + filter_at(vars(cols), search_function(. %in% search_result)) %>% + pull("row_number") rows <- rows[rows %in% row_filter] x[rows, "MDRO"] <<- to x[rows, "reason"] <<- paste0(any_all, " of the required antibiotics ", ifelse(any_all == "any", "is", "are"), " R") @@ -479,7 +495,7 @@ mdro <- function(x, if (verbose == TRUE) { x[rows, "columns_nonsusceptible"] <<- sapply(rows, function(row, group_vct = lst_vector) { - cols_nonsus <- sapply(x[row, group_vct, drop = FALSE], function(y) y %in% c("I", "R")) + cols_nonsus <- sapply(x[row, group_vct, drop = FALSE], function(y) y %in% search_result) paste(sort(names(cols_nonsus)[cols_nonsus]), collapse = ", ") }) } @@ -487,14 +503,14 @@ mdro <- function(x, function(row, group_tbl = lst) { sum(sapply(group_tbl, function(group) { - any(x[row, group[!is.na(group)]] == "R", na.rm = TRUE) | - any(x[row, group[!is.na(group)]] == "I", na.rm = TRUE) + any(unlist(x[row, group[!is.na(group)], drop = TRUE]) %in% search_result, na.rm = TRUE) }), na.rm = TRUE) }) + # for PDR; all agents are R (or I if combine_SI = FALSE) x[filter_at(x[rows, ], vars(lst_vector), - all_vars(. %in% c("R", "I")))$row_number, "classes_affected"] <<- 999 + all_vars(. %in% search_result))$row_number, "classes_affected"] <<- 999 } if (info == TRUE) { diff --git a/R/mic.R b/R/mic.R index 25211016..dcdd17bc 100755 --- a/R/mic.R +++ b/R/mic.R @@ -27,7 +27,7 @@ #' @param na.rm a logical indicating whether missing values should be removed #' @details Interpret MIC values as RSI values with \code{\link{as.rsi}}. It supports guidelines from EUCAST and CLSI. #' @return Ordered factor with new class \code{mic} -#' @keywords mic +#' @aliases MIC #' @export #' @importFrom dplyr %>% #' @seealso \code{\link{as.rsi}} diff --git a/R/portion.R b/R/portion.R index 7357eb32..5c52a26c 100755 --- a/R/portion.R +++ b/R/portion.R @@ -79,7 +79,6 @@ #' #' Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html} #' @seealso \code{\link[AMR]{count}_*} to count resistant and susceptible isolates. -#' @keywords resistance susceptibility rsi_df rsi antibiotics isolate isolates #' @return Double or, when \code{as_percent = TRUE}, a character. #' @rdname portion #' @name portion diff --git a/R/rsi.R b/R/rsi.R index a076a45d..1cd4286e 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -36,7 +36,7 @@ #' #' The function \code{is.rsi.eligible} returns \code{TRUE} when a columns contains at most 5\% invalid antimicrobial interpretations (not S and/or I and/or R), and \code{FALSE} otherwise. The threshold of 5\% can be set with the \code{threshold} parameter. #' @section Interpretation of S, I and R: -#' In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". +#' In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". #' #' \itemize{ #' \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} @@ -48,7 +48,7 @@ #' #' This AMR package honours this new insight. Use \code{\link{portion_SI}} to determine antimicrobial susceptibility and \code{\link{count_SI}} to count susceptible isolates. #' @return Ordered factor with new class \code{rsi} -#' @keywords rsi +#' @aliases RSI #' @export #' @importFrom dplyr %>% desc arrange filter #' @seealso \code{\link{as.mic}} diff --git a/appveyor.yml b/appveyor.yml index 509b4db9..bdc06413 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,7 +23,7 @@ init: ps: | $ErrorActionPreference = "Stop" - Invoke-WebRequest https://raw.githubusercontent.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" + Invoke-WebRequest https://gitlab.com/msberends/AMR/raw/master/tests/appveyor/appveyor_tool.ps1 -OutFile "..\appveyor-tool.ps1" Import-Module '..\appveyor-tool.ps1' install: diff --git a/docs/404.html b/docs/404.html index e261a7c3..ed984d46 100644 --- a/docs/404.html +++ b/docs/404.html @@ -84,7 +84,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 8e7621ad..783ceac4 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -84,7 +84,7 @@ diff --git a/docs/articles/index.html b/docs/articles/index.html index 8a908532..90367097 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -84,7 +84,7 @@ diff --git a/docs/authors.html b/docs/authors.html index a63e8fc5..dd7f8996 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -84,7 +84,7 @@ diff --git a/docs/index.html b/docs/index.html index 3012afaf..00399fb6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -45,7 +45,7 @@ diff --git a/docs/news/index.html b/docs/news/index.html index ba49411c..b35615e7 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -84,7 +84,7 @@ @@ -231,11 +231,11 @@ -Last updated: 05-Nov-2019
+Last updated: 06-Nov-2019
as.mo(..., allow_uncertain = 3)
Contents
In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below (http://www.eucast.org/newsiandr/). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".
+In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (http://www.eucast.org/newsiandr/). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".
S - Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.
I - Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.
In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below (http://www.eucast.org/newsiandr/). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".
+In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (http://www.eucast.org/newsiandr/). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".
S - Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.
I - Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.
mdro(x, guideline = NULL, col_mo = NULL, info = TRUE, - verbose = FALSE, pct_required_classes = 0.5, ...) + pct_required_classes = 0.5, combine_SI = TRUE, verbose = FALSE, + ...) brmo(x, guideline = "BRMO", ...) @@ -269,14 +270,18 @@info - print progress
- verbose -- a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.
+ pct_required_classes minimal required percentage of antimicrobial classes that must be available per isolate, rounded down. For example, with the default guideline, 17 antimicrobial classes must be available for S. aureus. Setting this
pct_required_classes
argument to0.5
(default) means that for every S. aureus isolate at least 8 different classes must be available. Any lower number of available classes will returnNA
for that isolate.+ +combine_SI ++ a logical to indicate whether all values of S and I must be merged into one, so resistance is only considered when isolates are R, not I. As this is the default behaviour of the
mdro()
function, it follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. When usingcombine_SI = FALSE
, resistance is considered when isolates are R or I.+ verbose ++ a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.
... @@ -394,6 +399,19 @@ TMP: trimethoprim (J01EA01), SXT: trimethoprim/sulfamethoxazole (J01EE01), VAN: vancomycin (J01XA01). + column name of an antibiotic, see section Antibiotics
Interpretation of S, I and R
+ + + +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (http://www.eucast.org/newsiandr/). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".
++
+ +- +
S - Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.
- +
I - Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.
- +
R - Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.
Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.
+This AMR package honours this new insight. Use
portion_SI
to determine antimicrobial susceptibility andcount_SI
to count susceptible isolates.Read more on our website!
@@ -427,6 +445,7 @@Value Details Antibiotics +Interpretation of S, I and R Read more on our website! Examples diff --git a/docs/reference/portion.html b/docs/reference/portion.html index 2bbfd81a..4cc9fdb4 100644 --- a/docs/reference/portion.html +++ b/docs/reference/portion.html @@ -86,7 +86,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port @@ -353,7 +353,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port -In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below (http://www.eucast.org/newsiandr/). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".
+In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (http://www.eucast.org/newsiandr/). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".
S - Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.
- diff --git a/man/ab_property.Rd b/man/ab_property.Rd index 03e643d9..af3bb84e 100644 --- a/man/ab_property.Rd +++ b/man/ab_property.Rd @@ -4,6 +4,7 @@ \alias{ab_property} \alias{ab_name} \alias{ab_atc} +\alias{ATC} \alias{ab_cid} \alias{ab_synonyms} \alias{ab_tradenames} diff --git a/man/age_groups.Rd b/man/age_groups.Rd index ea760e19..8272e578 100644 --- a/man/age_groups.Rd +++ b/man/age_groups.Rd @@ -74,5 +74,3 @@ example_isolates \%>\% \seealso{ To determine ages, based on one or more reference dates, use the \code{\link{age}} function. } -\keyword{age} -\keyword{age_group} diff --git a/man/as.ab.Rd b/man/as.ab.Rd index ab111a78..745b185c 100644 --- a/man/as.ab.Rd +++ b/man/as.ab.Rd @@ -72,4 +72,3 @@ ab_name("eryt") # "Erythromycin" \seealso{ \code{\link{antibiotics}} for the dataframe that is being used to determine ATCs. } -\keyword{atc} diff --git a/man/as.disk.Rd b/man/as.disk.Rd index 463e13d7..ccbc1d3a 100644 --- a/man/as.disk.Rd +++ b/man/as.disk.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/disk.R \name{as.disk} \alias{as.disk} +\alias{disk} \alias{is.disk} \title{Class 'disk'} \usage{ @@ -42,4 +43,3 @@ as.rsi(x = 12, \seealso{ \code{\link{as.rsi}} } -\keyword{disk} diff --git a/man/as.mic.Rd b/man/as.mic.Rd index 25a09b47..34e7acf5 100755 --- a/man/as.mic.Rd +++ b/man/as.mic.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/mic.R \name{as.mic} \alias{as.mic} +\alias{MIC} \alias{is.mic} \title{Class 'mic'} \usage{ @@ -52,4 +53,3 @@ freq(mic_data) \seealso{ \code{\link{as.rsi}} } -\keyword{mic} diff --git a/man/as.rsi.Rd b/man/as.rsi.Rd index 90faf7e4..ab14187f 100755 --- a/man/as.rsi.Rd +++ b/man/as.rsi.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/rsi.R \name{as.rsi} \alias{as.rsi} +\alias{RSI} \alias{as.rsi.mic} \alias{as.rsi.disk} \alias{as.rsi.data.frame} @@ -52,7 +53,7 @@ The function \code{is.rsi.eligible} returns \code{TRUE} when a columns contains } \section{Interpretation of S, I and R}{ -In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". \itemize{ \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} @@ -110,4 +111,3 @@ is.rsi.eligible(WHONET$`First name`, threshold = 0.99) # succeeds \seealso{ \code{\link{as.mic}} } -\keyword{rsi} diff --git a/man/count.Rd b/man/count.Rd index bd483f27..34d5fa4d 100644 --- a/man/count.Rd +++ b/man/count.Rd @@ -66,7 +66,7 @@ The function \code{rsi_df} works exactly like \code{count_df}, but adds the perc } \section{Interpretation of S, I and R}{ -In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". \itemize{ \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} @@ -182,9 +182,3 @@ example_isolates \%>\% \seealso{ \code{\link{portion}_*} to calculate microbial resistance and susceptibility. } -\keyword{antibiotics} -\keyword{isolate} -\keyword{isolates} -\keyword{resistance} -\keyword{rsi} -\keyword{susceptibility} diff --git a/man/eucast_rules.Rd b/man/eucast_rules.Rd index f2085a29..97a982fd 100644 --- a/man/eucast_rules.Rd +++ b/man/eucast_rules.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/eucast_rules.R \name{eucast_rules} \alias{eucast_rules} +\alias{EUCAST} \title{EUCAST rules} \source{ \itemize{ @@ -183,7 +184,3 @@ b c <- eucast_rules(a, verbose = TRUE) } } -\keyword{eucast} -\keyword{interpretive} -\keyword{reading} -\keyword{resistance} diff --git a/man/filter_ab_class.Rd b/man/filter_ab_class.Rd index 237f955d..9bb77f0d 100644 --- a/man/filter_ab_class.Rd +++ b/man/filter_ab_class.Rd @@ -89,5 +89,3 @@ example_isolates \%>\% filter_aminoglycosides("R", "all") \%>\% filter_fluoroquinolones("R", "all") } -\keyword{fillter_class} -\keyword{filter} diff --git a/man/first_isolate.Rd b/man/first_isolate.Rd index 3cad54fd..8cf2639b 100755 --- a/man/first_isolate.Rd +++ b/man/first_isolate.Rd @@ -160,6 +160,3 @@ x$first_blood_isolate <- first_isolate(x, specimen_group = "Blood") \seealso{ \code{\link{key_antibiotics}} } -\keyword{first} -\keyword{isolate} -\keyword{isolates} diff --git a/man/g.test.Rd b/man/g.test.Rd index 36a04119..a0f633dd 100644 --- a/man/g.test.Rd +++ b/man/g.test.Rd @@ -145,4 +145,3 @@ g.test(x) \seealso{ \code{\link{chisq.test}} } -\keyword{chi} diff --git a/man/like.Rd b/man/like.Rd index 35e15b7e..7ed6f949 100755 --- a/man/like.Rd +++ b/man/like.Rd @@ -63,9 +63,8 @@ a \%like\% b # get frequencies of bacteria whose name start with 'Ent' or 'ent' library(dplyr) example_isolates \%>\% - left_join_microorganisms() \%>\% - filter(genus \%like\% '^ent') \%>\% - freq(genus, species) + filter(mo_genus(mo) \%like\% '^ent') \%>\% + freq(mo_fullname(mo)) } \seealso{ \code{\link[base]{grep}} diff --git a/man/mdro.Rd b/man/mdro.Rd index a714112a..3ec5afd0 100644 --- a/man/mdro.Rd +++ b/man/mdro.Rd @@ -2,6 +2,12 @@ % Please edit documentation in R/mdro.R \name{mdro} \alias{mdro} +\alias{MDR} +\alias{XDR} +\alias{PDR} +\alias{BRMO} +\alias{3MRGN} +\alias{4MRGN} \alias{brmo} \alias{mrgn} \alias{mdr_tb} @@ -13,7 +19,8 @@ Please see Details for the list of publications used for this function. } \usage{ mdro(x, guideline = NULL, col_mo = NULL, info = TRUE, - verbose = FALSE, pct_required_classes = 0.5, ...) + pct_required_classes = 0.5, combine_SI = TRUE, verbose = FALSE, + ...) brmo(x, guideline = "BRMO", ...) @@ -34,10 +41,12 @@ eucast_exceptional_phenotypes(x, guideline = "EUCAST", ...) \item{info}{print progress} -\item{verbose}{a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.} - \item{pct_required_classes}{minimal required percentage of antimicrobial classes that must be available per isolate, rounded down. For example, with the default guideline, 17 antimicrobial classes must be available for \emph{S. aureus}. Setting this \code{pct_required_classes} argument to \code{0.5} (default) means that for every \emph{S. aureus} isolate at least 8 different classes must be available. Any lower number of available classes will return \code{NA} for that isolate.} +\item{combine_SI}{a logical to indicate whether all values of S and I must be merged into one, so resistance is only considered when isolates are R, not I. As this is the default behaviour of the \code{mdro()} function, it follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. When using \code{combine_SI = FALSE}, resistance is considered when isolates are R or I.} + +\item{verbose}{a logical to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.} + \item{...}{column name of an antibiotic, see section Antibiotics} } \value{ @@ -154,6 +163,21 @@ The following antibiotics are used for the functions \code{\link{eucast_rules}} \strong{VAN}: vancomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XA01}{J01XA01}). } +\section{Interpretation of S, I and R}{ + +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". + +\itemize{ + \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} + \item{\strong{I} - }{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.} + \item{\strong{R} - }{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.} +} + +Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. + +This AMR package honours this new insight. Use \code{\link{portion_SI}} to determine antimicrobial susceptibility and \code{\link{count_SI}} to count susceptible isolates. +} + \section{Read more on our website!}{ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. diff --git a/man/portion.Rd b/man/portion.Rd index eedfb654..722e1280 100644 --- a/man/portion.Rd +++ b/man/portion.Rd @@ -114,7 +114,7 @@ Using \code{only_all_tested} has no impact when only using one antibiotic as inp \section{Interpretation of S, I and R}{ -In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". +In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (\url{http://www.eucast.org/newsiandr/}). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations". \itemize{ \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.} @@ -226,10 +226,3 @@ my_table \%>\% \seealso{ \code{\link[AMR]{count}_*} to count resistant and susceptible isolates. } -\keyword{antibiotics} -\keyword{isolate} -\keyword{isolates} -\keyword{resistance} -\keyword{rsi} -\keyword{rsi_df} -\keyword{susceptibility} diff --git a/tests/appveyor/appveyor_tool.ps1 b/tests/appveyor/appveyor_tool.ps1 new file mode 100644 index 00000000..8586f9ed --- /dev/null +++ b/tests/appveyor/appveyor_tool.ps1 @@ -0,0 +1,193 @@ +if ( -not(Test-Path Env:\CRAN) ) { + $CRAN = "https://cran.rstudio.com" +} +Else { + $CRAN = $env:CRAN +} + + +# Found at http://zduck.com/2012/powershell-batch-files-exit-codes/ +Function Exec +{ + [CmdletBinding()] + param ( + [Parameter(Position=0, Mandatory=1)] + [scriptblock]$Command, + [Parameter(Position=1, Mandatory=0)] + [string]$ErrorMessage = "Execution of command failed.`n$Command" + ) + $ErrorActionPreference = "Continue" + & $Command 2>&1 | %{ "$_" } + if ($LastExitCode -ne 0) { + throw "Exec: $ErrorMessage`nExit code: $LastExitCode" + } +} + +Function Progress +{ + [CmdletBinding()] + param ( + [Parameter(Position=0, Mandatory=0)] + [string]$Message = "" + ) + + $ProgressMessage = '== ' + (Get-Date) + ': ' + $Message + + Write-Host $ProgressMessage -ForegroundColor Magenta +} + +Function TravisTool +{ + [CmdletBinding()] + param ( + [Parameter(Position=0, Mandatory=1)] + [string[]]$Params + ) + + Exec { bash.exe ../travis_tool.sh $Params } +} + +Function InstallR { + [CmdletBinding()] + Param() + + if ( -not(Test-Path Env:\R_VERSION) ) { + $version = "patched" + } + Else { + $version = $env:R_VERSION + } + + if ( -not(Test-Path Env:\R_ARCH) ) { + $arch = "x64" + } + Else { + $arch = $env:R_ARCH + } + + If ($arch -eq "i386") { + $mingw_path = "mingw_32" + } + Else { + $mingw_path = "mingw_64" + } + + Progress ("Version: " + $version) + + If ($version -eq "devel") { + $url_path = "" + $version = "devel" + } + ElseIf (($version -eq "stable") -or ($version -eq "release")) { + $url_path = "" + $version = $(ConvertFrom-JSON $(Invoke-WebRequest http://rversions.r-pkg.org/r-release-win).Content).version + If ($version -eq "3.2.4") { + $version = "3.2.4revised" + } + } + ElseIf ($version -eq "patched") { + $url_path = "" + $version = $(ConvertFrom-JSON $(Invoke-WebRequest http://rversions.r-pkg.org/r-release-win).Content).version + "patched" + } + ElseIf ($version -eq "oldrel") { + $version = $(ConvertFrom-JSON $(Invoke-WebRequest http://rversions.r-pkg.org/r-oldrel).Content).version + $url_path = ("old/" + $version + "/") + } + Else { + $url_path = ("old/" + $version + "/") + } + + Progress ("URL path: " + $url_path) + + $rurl = $CRAN + "/bin/windows/base/" + $url_path + "R-" + $version + "-win.exe" + + Progress ("Downloading R from: " + $rurl) + & "C:\Program Files\Git\mingw64\bin\curl.exe" -s -o ../R-win.exe -L $rurl + + Progress "Running R installer" + Start-Process -FilePath ..\R-win.exe -ArgumentList "/VERYSILENT /DIR=C:\R" -NoNewWindow -Wait + + $RDrive = "C:" + echo "R is now available on drive $RDrive" + + Progress "Setting PATH" + $env:PATH = $RDrive + '\R\bin\' + $arch + ';' + 'C:\Rtools\' + $mingw_path + '\bin;' + 'C:\MinGW\msys\1.0\bin;' + $env:PATH + + Progress "Testing R installation" + Rscript -e "sessionInfo()" +} + +Function InstallRtools { + if ( -not(Test-Path Env:\RTOOLS_VERSION) ) { + Progress "Determining Rtools version" + $rtoolsver = $(Invoke-WebRequest ($CRAN + "/bin/windows/Rtools/VERSION.txt")).Content.Split(' ')[2].Split('.')[0..1] -Join '' + } + Else { + $rtoolsver = $env:RTOOLS_VERSION + } + + $rtoolsurl = $CRAN + "/bin/windows/Rtools/Rtools$rtoolsver.exe" + + Progress ("Downloading Rtools from: " + $rtoolsurl) + & "C:\Program Files\Git\mingw64\bin\curl.exe" -s -o ../Rtools-current.exe -L $rtoolsurl + + Progress "Running Rtools installer" + Start-Process -FilePath ..\Rtools-current.exe -ArgumentList /VERYSILENT -NoNewWindow -Wait + + $RtoolsDrive = "C:" + echo "Rtools is now available on drive $RtoolsDrive" + + Progress "Setting PATH" + if ( -not(Test-Path Env:\GCC_PATH) ) { + $gcc_path = "gcc-4.6.3" + } + Else { + $gcc_path = $env:GCC_PATH + } + $env:PATH = $RtoolsDrive + '\Rtools\bin;' + $RtoolsDrive + '\Rtools\MinGW\bin;' + $RtoolsDrive + '\Rtools\' + $gcc_path + '\bin;' + $env:PATH + $env:BINPREF=$RtoolsDrive + '/Rtools/mingw_$(WIN)/bin/' +} + +Function Bootstrap { + [CmdletBinding()] + Param() + + Progress "Bootstrap: Start" + + Progress "Adding GnuWin32 tools to PATH" + $env:PATH = "C:\Program Files (x86)\Git\bin;" + $env:PATH + + Progress "Setting time zone" + tzutil /g + tzutil /s "GMT Standard Time" + tzutil /g + + InstallR + + if ((Test-Path "src") -or ($env:USE_RTOOLS -eq "true") -or ($env:USE_RTOOLS -eq "yes")) { + InstallRtools + } + Else { + Progress "Skipping download of Rtools because src/ directory is missing." + } + + Progress "Downloading and installing travis_tool.sh" + Invoke-WebRequest https://gitlab.com/msberends/AMR/raw/master/tests/appveyor/travis_tool.sh -OutFile "..\travis_tool.sh" + echo '@bash.exe ../travis_tool.sh %*' | Out-File -Encoding ASCII .\travis_tool.sh.cmd + cat .\travis_tool.sh.cmd + bash -c "( echo; echo '^travis_tool\.sh\.cmd$' ) >> .Rbuildignore" + cat .\.Rbuildignore + + $env:PATH.Split(";") + + Progress "Setting R_LIBS_USER" + $env:R_LIBS_USER = 'c:\RLibrary' + if ( -not(Test-Path $env:R_LIBS_USER) ) { + mkdir $env:R_LIBS_USER + } + + Progress "Setting TAR to 'internal'" + $env:TAR = 'internal' + + Progress "Bootstrap: Done" +} diff --git a/tests/appveyor/travis_tool.sh b/tests/appveyor/travis_tool.sh new file mode 100644 index 00000000..5d9caf61 --- /dev/null +++ b/tests/appveyor/travis_tool.sh @@ -0,0 +1,428 @@ +#!/bin/bash +# -*- sh-basic-offset: 4; sh-indentation: 4 -*- +# Bootstrap an R/travis environment. + +set -e +# Comment out this line for quieter output: +set -x + +CRAN=${CRAN:-"https://cran.rstudio.com"} +BIOC=${BIOC:-"http://bioconductor.org/biocLite.R"} +PKGTYPE=${PKGTYPE:-"win.binary"} +BIOC_USE_DEVEL=${BIOC_USE_DEVEL:-"TRUE"} +OS=$(uname -s) +DOWNLOAD_FILE_METHOD=${DOWNLOAD_FILE_METHOD:-"auto"} + +PANDOC_VERSION='1.13.1' +PANDOC_DIR="${HOME}/opt/pandoc" +PANDOC_URL="https://s3.amazonaws.com/rstudio-buildtools/pandoc-${PANDOC_VERSION}.zip" + +# MacTeX installs in a new $PATH entry, and there's no way to force +# the *parent* shell to source it from here. So we just manually add +# all the entries to a location we already know to be on $PATH. +# +# TODO(craigcitro): Remove this once we can add `/usr/texbin` to the +# root path. +PATH="${PATH}:/usr/texbin" + +R_BUILD_ARGS=${R_BUILD_ARGS-"--no-manual"} +R_CHECK_ARGS=${R_CHECK_ARGS-"--no-manual --as-cran"} + +R_VERSION_TEST="getRversion() >= '3.5.0'" + +R_USE_BIOC_INST="source('${BIOC}');"\ +" tryCatch(useDevel(${BIOC_USE_DEVEL}),"\ +" error=function(e) {if (!grepl('already in use', e$message)) {e}});"\ +" options(repos=biocinstallRepos())" + +R_USE_BIOC_MNGR="if (!requireNamespace('BiocManager', quietly=TRUE))"\ +" install.packages('BiocManager', repos=c(CRAN='${CRAN}'));"\ +" if (${BIOC_USE_DEVEL})"\ +" BiocManager::install(version = 'devel', ask = FALSE);"\ +" options(repos=BiocManager::repositories())" + +R_USE_BIOC_CMDS="if (${R_VERSION_TEST}) {${R_USE_BIOC_MNGR}} else {${R_USE_BIOC_INST}};" + +BIOC_INSTALL="{if (${R_VERSION_TEST}) BiocManager::install else BiocInstaller::biocLite}" + +Bootstrap() { + if [[ "Darwin" == "${OS}" ]]; then + BootstrapMac + elif [[ "Linux" == "${OS}" ]]; then + BootstrapLinux + else + echo "Unknown OS: ${OS}" + exit 1 + fi + + if ! (test -e .Rbuildignore && grep -q 'travis-tool' .Rbuildignore); then + echo '^travis-tool\.sh$' >>.Rbuildignore + fi +} + +InstallPandoc() { + local os_path="$1" + mkdir -p "${PANDOC_DIR}" + curl -o /tmp/pandoc-${PANDOC_VERSION}.zip ${PANDOC_URL} + unzip -j /tmp/pandoc-${PANDOC_VERSION}.zip "pandoc-${PANDOC_VERSION}/${os_path}/pandoc" -d "${PANDOC_DIR}" + chmod +x "${PANDOC_DIR}/pandoc" + sudo ln -s "${PANDOC_DIR}/pandoc" /usr/local/bin + unzip -j /tmp/pandoc-${PANDOC_VERSION}.zip "pandoc-${PANDOC_VERSION}/${os_path}/pandoc-citeproc" -d "${PANDOC_DIR}" + chmod +x "${PANDOC_DIR}/pandoc-citeproc" + sudo ln -s "${PANDOC_DIR}/pandoc-citeproc" /usr/local/bin +} + +BootstrapLinux() { + # Set up our CRAN mirror. + sudo add-apt-repository "deb ${CRAN}/bin/linux/ubuntu $(lsb_release -cs)/" + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 + + # Add marutter's c2d4u repository. + sudo add-apt-repository -y "ppa:marutter/rrutter" + sudo add-apt-repository -y "ppa:marutter/c2d4u" + + # Update after adding all repositories. Retry several times to work around + # flaky connection to Launchpad PPAs. + Retry sudo apt-get update -qq + + # Install an R development environment. qpdf is also needed for + # --as-cran checks: + # https://stat.ethz.ch/pipermail/r-help//2012-September/335676.html + Retry sudo apt-get install -y --no-install-recommends r-base-dev r-recommended qpdf + + # Change permissions for /usr/local/lib/R/site-library + # This should really be via 'staff adduser travis staff' + # but that may affect only the next shell + sudo chmod 2777 /usr/local/lib/R /usr/local/lib/R/site-library + + # Process options + BootstrapLinuxOptions +} + +BootstrapLinuxOptions() { + if [[ -n "$BOOTSTRAP_LATEX" ]]; then + # We add a backports PPA for more recent TeX packages. + sudo add-apt-repository -y "ppa:texlive-backports/ppa" + + Retry sudo apt-get install -y --no-install-recommends \ + texlive-base texlive-latex-base texlive-generic-recommended \ + texlive-fonts-recommended texlive-fonts-extra \ + texlive-extra-utils texlive-latex-recommended texlive-latex-extra \ + texinfo lmodern + fi + if [[ -n "$BOOTSTRAP_PANDOC" ]]; then + InstallPandoc 'linux/debian/x86_64' + fi +} + +BootstrapMac() { + # Install from latest CRAN binary build for OS X + wget ${CRAN}/bin/macosx/R-latest.pkg -O /tmp/R-latest.pkg + + echo "Installing OS X binary package for R" + sudo installer -pkg "/tmp/R-latest.pkg" -target / + rm "/tmp/R-latest.pkg" + + # Process options + BootstrapMacOptions +} + +BootstrapMacOptions() { + if [[ -n "$BOOTSTRAP_LATEX" ]]; then + # TODO: Install MacTeX.pkg once there's enough disk space + MACTEX=BasicTeX.pkg + wget http://ctan.math.utah.edu/ctan/tex-archive/systems/mac/mactex/$MACTEX -O "/tmp/$MACTEX" + + echo "Installing OS X binary package for MacTeX" + sudo installer -pkg "/tmp/$MACTEX" -target / + rm "/tmp/$MACTEX" + # We need a few more packages than the basic package provides; this + # post saved me so much pain: + # https://stat.ethz.ch/pipermail/r-sig-mac/2010-May/007399.html + sudo tlmgr update --self + sudo tlmgr install inconsolata upquote courier courier-scaled helvetic + fi + if [[ -n "$BOOTSTRAP_PANDOC" ]]; then + InstallPandoc 'mac' + fi +} + +EnsureDevtools() { + if ! Rscript -e 'if (!("devtools" %in% rownames(installed.packages()))) q(status=1)' ; then + # Install devtools and testthat. + RBinaryInstall devtools testthat + fi +} + +EnsureRemotes() { + if ! Rscript -e 'if (!("remotes" %in% rownames(installed.packages()))) q(status=1)' ; then + # Install remotes. + RBinaryInstall remotes + fi + if ! Rscript -e 'if (!("remotes" %in% rownames(installed.packages()))) q(status=1)' ; then + # Fallback: Install remotes from URL. + Rscript -e 'path <- file.path(tempdir(), "remotes_1.0.0.tar.gz"); download.file("https://cran.rstudio.com/src/contrib/Archive/remotes/remotes_1.0.0.tar.gz", path); install.packages(path, repos = NULL, type = "source")' + fi +} + +AptGetInstall() { + if [[ "Linux" != "${OS}" ]]; then + echo "Wrong OS: ${OS}" + exit 1 + fi + + if [[ "" == "$*" ]]; then + echo "No arguments to aptget_install" + exit 1 + fi + + echo "Installing apt package(s) $@" + Retry sudo apt-get -y install "$@" +} + +DpkgCurlInstall() { + if [[ "Linux" != "${OS}" ]]; then + echo "Wrong OS: ${OS}" + exit 1 + fi + + if [[ "" == "$*" ]]; then + echo "No arguments to dpkgcurl_install" + exit 1 + fi + + echo "Installing remote package(s) $@" + for rf in "$@"; do + curl -OL ${rf} + f=$(basename ${rf}) + sudo dpkg -i ${f} + rm -v ${f} + done +} + +RInstall() { + if [[ "" == "$*" ]]; then + echo "No arguments to r_install" + exit 1 + fi + + echo "Installing R package(s): $@" + Rscript -e 'install.packages(commandArgs(TRUE), repos="'"${CRAN}"'", INSTALL_opts="", type="'"${PKGTYPE}"'")' "$@" +} + +BiocInstall() { + if [[ "" == "$*" ]]; then + echo "No arguments to bioc_install" + exit 1 + fi + + echo "Installing R Bioconductor package(s): $@" + Rscript -e "${R_USE_BIOC_CMDS}"" ${BIOC_INSTALL}(commandArgs(TRUE))" "$@" +} + +RBinaryInstall() { + if [[ -z "$#" ]]; then + echo "No arguments to r_binary_install" + exit 1 + fi + + if [[ "Linux" != "${OS}" ]] || [[ -n "${FORCE_SOURCE_INSTALL}" ]]; then + echo "Fallback: Installing from source" + RInstall "$@" + return + fi + + echo "Installing *binary* R packages: $*" + r_packages=$(echo $* | tr '[:upper:]' '[:lower:]') + r_debs=$(for r_package in ${r_packages}; do echo -n "r-cran-${r_package} "; done) + + AptGetInstall ${r_debs} +} + +InstallGithub() { + EnsureRemotes + + echo "Installing GitHub packages: $@" + # Install the package. + Rscript -e 'options(repos = c(CRAN = "'"${CRAN}"'"), download.file.method = "'"${DOWNLOAD_FILE_METHOD}"'"); remotes::install_github(commandArgs(TRUE), type="'"${PKGTYPE}"'")' "$@" +} + +InstallDeps() { + EnsureRemotes + + echo "Installing dependencies" + Rscript -e 'options(repos = c(CRAN = "'"${CRAN}"'"), download.file.method = "'"${DOWNLOAD_FILE_METHOD}"'"); remotes::install_deps(dependencies = TRUE, type="'"${PKGTYPE}"'")' +} + +InstallBiocDeps() { + EnsureDevtools + Rscript -e "${R_USE_BIOC_CMDS}"' library(devtools); install_deps(dependencies = TRUE, type="'"${PKGTYPE}"'")' +} + +DumpSysinfo() { + echo "Dumping system information." + R -e '.libPaths(); sessionInfo(); installed.packages()' +} + +DumpLogsByExtension() { + if [[ -z "$1" ]]; then + echo "dump_logs_by_extension requires exactly one argument, got: $@" + exit 1 + fi + extension=$1 + shift + package=$(find . -maxdepth 1 -name "*.Rcheck" -type d) + if [[ ${#package[@]} -ne 1 ]]; then + echo "Could not find package Rcheck directory, skipping log dump." + exit 0 + fi + for name in $(find "${package}" -type f -name "*${extension}"); do + echo ">>> Filename: ${name} <<<" + cat ${name} + done +} + +DumpLogs() { + echo "Dumping test execution logs." + DumpLogsByExtension "out" + DumpLogsByExtension "log" + DumpLogsByExtension "fail" +} + +RunTests() { + echo "Building with: R CMD build ${R_BUILD_ARGS}" + if [[ "${KEEP_VIGNETTES}" == "" ]]; then + if [[ "${OS:0:5}" == "MINGW" || "${OS:0:4}" == "MSYS" ]]; then + if [[ -d vignettes ]]; then + rm -rf vignettes + Rscript -e "d <- read.dcf('DESCRIPTION'); d[, colnames(d) == 'VignetteBuilder'] <- NA; write.dcf(d, 'DESCRIPTION')" + fi + fi + fi + R CMD build ${R_BUILD_ARGS} . + # We want to grab the version we just built. + FILE=$(ls -1t *.tar.gz | head -n 1) + + # Create binary package (currently Windows only) + if [[ "${OS:0:5}" == "MINGW" || "${OS:0:4}" == "MSYS" ]]; then + R_CHECK_INSTALL_ARGS="--install-args=--build" + fi + + echo "Testing with: R CMD check \"${FILE}\" ${R_CHECK_ARGS} ${R_CHECK_INSTALL_ARGS}" + _R_CHECK_CRAN_INCOMING_=${_R_CHECK_CRAN_INCOMING_:-FALSE} + if [[ "$_R_CHECK_CRAN_INCOMING_" == "FALSE" ]]; then + echo "(CRAN incoming checks are off)" + fi + _R_CHECK_CRAN_INCOMING_=${_R_CHECK_CRAN_INCOMING_} R_QPDF=true R CMD check "${FILE}" ${R_CHECK_ARGS} ${R_CHECK_INSTALL_ARGS} + + # Check reverse dependencies + if [[ -n "$R_CHECK_REVDEP" ]]; then + echo "Checking reverse dependencies" + EnsureDevtools + Rscript -e 'library(devtools); checkOutput <- unlist(revdep_check(as.package(".")$package));if (!is.null(checkOutput)) {print(data.frame(pkg = names(checkOutput), error = checkOutput));for(i in seq_along(checkOutput)){;cat("\n", names(checkOutput)[i], " Check Output:\n ", paste(readLines(regmatches(checkOutput[i], regexec("/.*\\.out", checkOutput[i]))[[1]]), collapse = "\n ", sep = ""), "\n", sep = "")};q(status = 1, save = "no")}' + fi + + if [[ -n "${WARNINGS_ARE_ERRORS}" ]]; then + if DumpLogsByExtension "00check.log" | grep -q WARNING; then + echo "Found warnings, treated as errors." + echo "Clear or unset the WARNINGS_ARE_ERRORS environment variable to ignore warnings." + exit 1 + fi + fi +} + +Retry() { + if "$@"; then + return 0 + fi + for wait_time in 5 20 30 60; do + echo "Command failed, retrying in ${wait_time} ..." + sleep ${wait_time} + if "$@"; then + return 0 + fi + done + echo "Failed all retries!" + exit 1 +} + +COMMAND=$1 +echo "Running command: ${COMMAND}" +shift +case $COMMAND in + ## + ## Bootstrap a new core system + "bootstrap") + Bootstrap + ;; + ## + ## Ensure devtools is loaded (implicitly called) + "install_devtools"|"devtools_install") + EnsureDevtools + ;; + ## + ## Ensure remotes is loaded (implicitly called) + "install_remotes"|"remotes_install") + EnsureRemotes + ;; + ## + ## Install a binary deb package via apt-get + "install_aptget"|"aptget_install") + AptGetInstall "$@" + ;; + ## + ## Install a binary deb package via a curl call and local dpkg -i + "install_dpkgcurl"|"dpkgcurl_install") + DpkgCurlInstall "$@" + ;; + ## + ## Install an R dependency from CRAN + "install_r"|"r_install") + RInstall "$@" + ;; + ## + ## Install an R dependency from Bioconductor + "install_bioc"|"bioc_install") + BiocInstall "$@" + ;; + ## + ## Install an R dependency as a binary (via c2d4u PPA) + "install_r_binary"|"r_binary_install") + RBinaryInstall "$@" + ;; + ## + ## Install a package from github sources (needs remotes) + "install_github"|"github_package") + InstallGithub "$@" + ;; + ## + ## Install package dependencies from CRAN (needs remotes) + "install_deps") + InstallDeps + ;; + ## + ## Install package dependencies from Bioconductor and CRAN (needs devtools) + "install_bioc_deps") + InstallBiocDeps + ;; + ## + ## Run the actual tests, ie R CMD check + "run_tests") + RunTests + ;; + ## + ## Dump information about installed packages + "dump_sysinfo") + DumpSysinfo + ;; + ## + ## Dump build or check logs + "dump_logs") + DumpLogs + ;; + ## + ## Dump selected build or check logs + "dump_logs_by_extension") + DumpLogsByExtension "$@" + ;; +esac
I - Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.