mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 20:41:58 +02:00
(v1.1.0.9007) lose dependencies
This commit is contained in:
@ -32,6 +32,7 @@
|
||||
#' @examples
|
||||
#' availability(example_isolates)
|
||||
#'
|
||||
#' \dontrun{
|
||||
#' library(dplyr)
|
||||
#' example_isolates %>% availability()
|
||||
#'
|
||||
@ -43,6 +44,7 @@
|
||||
#' filter(mo == as.mo("E. coli")) %>%
|
||||
#' select_if(is.rsi) %>%
|
||||
#' availability()
|
||||
#' }
|
||||
availability <- function(tbl, width = NULL) {
|
||||
x <- base::sapply(tbl, function(x) {
|
||||
1 - base::sum(base::is.na(x)) / base::length(x)
|
||||
|
@ -69,7 +69,7 @@
|
||||
#' susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX)
|
||||
#'
|
||||
#'
|
||||
#' if (!require("dplyr")) {
|
||||
#' if (require("dplyr")) {
|
||||
#' example_isolates %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(R = count_R(CIP),
|
||||
|
2
R/disk.R
2
R/disk.R
@ -33,6 +33,7 @@
|
||||
#' @seealso [as.rsi()]
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' \dontrun{
|
||||
#' # transform existing disk zones to the `disk` class
|
||||
#' library(dplyr)
|
||||
#' df <- data.frame(microorganism = "E. coli",
|
||||
@ -50,6 +51,7 @@
|
||||
#' guideline = "EUCAST")
|
||||
#'
|
||||
#' as.rsi(df)
|
||||
#' }
|
||||
as.disk <- function(x, na.rm = FALSE) {
|
||||
if (is.disk(x)) {
|
||||
x
|
||||
|
@ -206,7 +206,8 @@ eucast_rules <- function(x,
|
||||
"\n\nThis may overwrite your existing data if you use e.g.:",
|
||||
"\ndata <- eucast_rules(data, verbose = TRUE)\n\nDo you want to continue?")
|
||||
if ("rstudioapi" %in% rownames(utils::installed.packages())) {
|
||||
q_continue <- rstudioapi::showQuestion("Using verbose = TRUE with eucast_rules()", txt)
|
||||
showQuestion <- get("showQuestion", envir = asNamespace("rstudioapi"))
|
||||
q_continue <- showQuestion("Using verbose = TRUE with eucast_rules()", txt)
|
||||
} else {
|
||||
q_continue <- utils::menu(choices = c("OK", "Cancel"), graphics = FALSE, title = txt)
|
||||
}
|
||||
|
@ -62,7 +62,7 @@
|
||||
#' @export
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' if (!require("ggplot2") & !require("dplyr")) {
|
||||
#' if (require("ggplot2") & require("dplyr")) {
|
||||
#'
|
||||
#' # get antimicrobial results for drugs against a UTI:
|
||||
#' ggplot(example_isolates %>% select(AMX, NIT, FOS, TMP, CIP)) +
|
||||
|
@ -73,6 +73,7 @@
|
||||
#' # `example_isolates` is a dataset available in the AMR package.
|
||||
#' # See ?example_isolates.
|
||||
#'
|
||||
#' \dontrun{
|
||||
#' library(dplyr)
|
||||
#' # set key antibiotics to a new variable
|
||||
#' my_patients <- example_isolates %>%
|
||||
@ -87,7 +88,7 @@
|
||||
#' # Check the difference, in this data set it results in 7% more isolates:
|
||||
#' sum(my_patients$first_regular, na.rm = TRUE)
|
||||
#' sum(my_patients$first_weighted, na.rm = TRUE)
|
||||
#'
|
||||
#' }
|
||||
#'
|
||||
#' # output of the `key_antibiotics` function could be like this:
|
||||
#' strainA <- "SSSRR.S.R..S"
|
||||
|
2
R/like.R
2
R/like.R
@ -57,10 +57,12 @@
|
||||
#' #> TRUE TRUE TRUE
|
||||
#'
|
||||
#' # get isolates whose name start with 'Ent' or 'ent'
|
||||
#' \dontrun{
|
||||
#' library(dplyr)
|
||||
#' example_isolates %>%
|
||||
#' filter(mo_name(mo) %like% "^ent") %>%
|
||||
#' freq(mo)
|
||||
#' }
|
||||
like <- function(x, pattern, ignore.case = TRUE) {
|
||||
# set to fixed if no regex found
|
||||
fixed <- all(!grepl("[$.^*?+}{|)(]", pattern))
|
||||
|
5
R/mdro.R
5
R/mdro.R
@ -66,7 +66,7 @@
|
||||
#' @source
|
||||
#' Please see *Details* for the list of publications used for this function.
|
||||
#' @examples
|
||||
#' \donttest{
|
||||
#' \dontrun{
|
||||
#' library(dplyr)
|
||||
#'
|
||||
#' example_isolates %>%
|
||||
@ -94,7 +94,8 @@ mdro <- function(x,
|
||||
"\n\nThis may overwrite your existing data if you use e.g.:",
|
||||
"\ndata <- mdro(data, verbose = TRUE)\n\nDo you want to continue?")
|
||||
if ("rstudioapi" %in% rownames(utils::installed.packages())) {
|
||||
q_continue <- rstudioapi::showQuestion("Using verbose = TRUE with mdro()", txt)
|
||||
showQuestion <- get("showQuestion", envir = asNamespace("rstudioapi"))
|
||||
q_continue <- showQuestion("Using verbose = TRUE with mdro()", txt)
|
||||
} else {
|
||||
q_continue <- utils::menu(choices = c("OK", "Cancel"), graphics = FALSE, title = txt)
|
||||
}
|
||||
|
@ -126,7 +126,8 @@ set_mo_source <- function(path) {
|
||||
} else if (path %like% "[.]xlsx?$") {
|
||||
# is Excel file (old or new)
|
||||
stopifnot_installed_package("readxl")
|
||||
df <- readxl::read_excel(path)
|
||||
read_excel <- get("read_excel", envir = asNamespace("readxl"))
|
||||
df <- read_excel(path)
|
||||
|
||||
} else if (path %like% "[.]tsv$") {
|
||||
df <- utils::read.table(header = TRUE, sep = "\t", stringsAsFactors = FALSE)
|
||||
|
@ -99,8 +99,7 @@
|
||||
#' proportion_IR(example_isolates$AMX)
|
||||
#' proportion_R(example_isolates$AMX)
|
||||
#'
|
||||
#' if (!require("dplyr")) {
|
||||
#' library(dplyr)
|
||||
#' if (require("dplyr")) {
|
||||
#' example_isolates %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(r = resistance(CIP),
|
||||
@ -157,7 +156,9 @@
|
||||
#' select(hospital_id, AMX, CIP) %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' proportion_df(translate = FALSE)
|
||||
#'
|
||||
#' }
|
||||
#'
|
||||
#' \dontrun{
|
||||
#' # calculate current empiric combination therapy of Helicobacter gastritis:
|
||||
#' my_table %>%
|
||||
#' filter(first_isolate == TRUE,
|
||||
|
@ -66,11 +66,12 @@
|
||||
#' year_min = 2010,
|
||||
#' model = "binomial")
|
||||
#' plot(x)
|
||||
#' ggplot_rsi_predict(x)
|
||||
#' if (require("ggplot2")) {
|
||||
#' ggplot_rsi_predict(x)
|
||||
#' }
|
||||
#'
|
||||
#' # using dplyr:
|
||||
#' if (!require("dplyr")) {
|
||||
#' library(dplyr)
|
||||
#' if (require("dplyr")) {
|
||||
#' x <- example_isolates %>%
|
||||
#' filter_first_isolate() %>%
|
||||
#' filter(mo_genus(mo) == "Staphylococcus") %>%
|
||||
@ -83,7 +84,7 @@
|
||||
#' }
|
||||
#'
|
||||
#' # create nice plots with ggplot2 yourself
|
||||
#' if (!require(ggplot2) & !require("dplyr")) {
|
||||
#' if (require(ggplot2) & require("dplyr")) {
|
||||
#'
|
||||
#' data <- example_isolates %>%
|
||||
#' filter(mo == as.mo("E. coli")) %>%
|
||||
|
4
R/rsi.R
4
R/rsi.R
@ -70,7 +70,7 @@
|
||||
#' NIT = as.mic(32))
|
||||
#' as.rsi(df)
|
||||
#'
|
||||
#' \donttest{
|
||||
#' \dontrun{
|
||||
#'
|
||||
#' # the dplyr way
|
||||
#' library(dplyr)
|
||||
@ -117,6 +117,7 @@
|
||||
#' plot(rsi_data) # for percentages
|
||||
#' barplot(rsi_data) # for frequencies
|
||||
#'
|
||||
#' \dontrun{
|
||||
#' library(dplyr)
|
||||
#' example_isolates %>%
|
||||
#' mutate_at(vars(PEN:RIF), as.rsi)
|
||||
@ -132,6 +133,7 @@
|
||||
#' # default threshold of `is.rsi.eligible` is 5%.
|
||||
#' is.rsi.eligible(WHONET$`First name`) # fails, >80% is invalid
|
||||
#' is.rsi.eligible(WHONET$`First name`, threshold = 0.99) # succeeds
|
||||
#' }
|
||||
as.rsi <- function(x, ...) {
|
||||
UseMethod("as.rsi")
|
||||
}
|
||||
|
Reference in New Issue
Block a user