diff --git a/DESCRIPTION b/DESCRIPTION index fb309447..ff75d4e8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.6.0.9012 -Date: 2021-04-27 +Version: 1.6.0.9013 +Date: 2021-04-29 Title: Antimicrobial Resistance Data Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index b23286fd..2b7dbd19 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,15 +1,14 @@ -# AMR 1.6.0.9012 -## Last updated: 27 April 2021 +# AMR 1.6.0.9013 +## Last updated: 29 April 2021 ### New * Function `custom_eucast_rules()` that brings support for custom AMR rules in `eucast_rules()` * Support for all four methods to determine first isolates as summarised by Hindler *et al* (doi: [10.1086/511864](https://doi.org/10.1086/511864)): isolate-based, patient-based, episode-based and phenotype-based. The last method is now the default. - * Since fungal isolates can also be selected, new functions `key_antimicrobials()` and `all_antimicrobials()` have replaced the now deprecated function `key_antibiotics()` - * Using `key_antimicrobials()` still only selects six preferred antibiotics for Gram-negatives, six for Gram-positives, and six universal antibiotics. It has a new `antifungal` argument to set antifungal agents (antimycotics). - * The `first_isolate()` function gained the argument `method` that has to be "phenotype-based", "episode-based", "patient-based", or "isolate-based". The old behaviour is equal to "episode-based", while the new default is "phenotype-based". + * The `first_isolate()` function gained the argument `method` that has to be "phenotype-based", "episode-based", "patient-based", or "isolate-based". The old behaviour is equal to "episode-based". The new default is "phenotype-based" if antimicrobial test results are available, and "episode-based" otherwise. This new default will yield slightly more isolates for selection (which is a good thing). + * Since fungal isolates can also be selected, the functions `key_antibiotics()` and `key_antibiotics_equal()` are now deprecated in favour of the `key_antimicrobials()` and `antimicrobial_equal()` functions. Also, the new `all_antimicrobials()` function works like the old `key_antibiotics()` function, but includes any column with antimicrobial test results. Using `key_antimicrobials()` still only selects six preferred antibiotics for Gram-negatives, six for Gram-positives, and six universal antibiotics. It has a new `antifungal` argument to set antifungal agents (antimycotics). * Using `type == "points"` in the `first_isolate()` function for phenotype-based selection will now consider all antimicrobial drugs in the data set, using the new `all_antimicrobials()` * The `first_isolate()` function can now take a vector of values for `col_keyantibiotics` and can have an episode length of `Inf` - * The `filter_first_isolate()` function has not changed, as it uses the episode-based method. The `filter_first_weighted_isolate()` may now include more isolates as uses the phenotype-based method. + * Since the phenotype-based method is the new default, `filter_first_isolate()` renders the `filter_first_weighted_isolate()` function redundant. For this reason, `filter_first_weighted_isolate()` is now deprecated. * The documentation of the `first_isolate()` and `key_antimicrobials()` functions has been completely rewritten. ### Changed diff --git a/R/deprecated.R b/R/deprecated.R index 0ac98c67..ba226b88 100755 --- a/R/deprecated.R +++ b/R/deprecated.R @@ -46,6 +46,31 @@ p_symbol <- function(p, emptychar = " ") { s } +#' @name AMR-deprecated +#' @export +filter_first_weighted_isolate <- function(x = NULL, + col_date = NULL, + col_patient_id = NULL, + col_mo = NULL, + ...) { + + .Deprecated(old = "filter_first_weighted_isolate()", + new = "filter_first_isolate()", + package = "AMR") + + if (is_null_or_grouped_tbl(x)) { + # when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all()) + # is also fix for using a grouped df as input (a dot as first argument) + x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x) + } + meet_criteria(x, allow_class = "data.frame") # also checks dimensions to be >0 + meet_criteria(col_date, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) + meet_criteria(col_patient_id, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) + meet_criteria(col_mo, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) + + filter_first_isolate(x = x, col_date = col_date, col_patient_id = col_patient_id, col_mo = col_mo, ...) +} + #' @name AMR-deprecated #' @export key_antibiotics <- function(x = NULL, diff --git a/R/episode.R b/R/episode.R index cfcd7998..d029e9bf 100644 --- a/R/episode.R +++ b/R/episode.R @@ -29,13 +29,13 @@ #' @inheritSection lifecycle Stable Lifecycle #' @param x vector of dates (class `Date` or `POSIXt`) #' @param episode_days required episode length in days, can also be less than a day or `Inf`, see *Details* -#' @param ... currently not used +#' @param ... ignored, only in place to allow future extensions #' @details #' Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least `episode_days` days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least `episode_days` days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored. #' -#' The [first_isolate()] function is a wrapper around the [is_new_episode()] function, but is more efficient for data sets containing microorganism codes or names. +#' The [first_isolate()] function is a wrapper around the [is_new_episode()] function, but is more efficient for data sets containing microorganism codes or names and allows for different isolate selection methods. #' -#' The `dplyr` package is not required for these functions to work, but these functions support [variable grouping][dplyr::group_by()] and work conveniently inside `dplyr` verbs such as [`filter()`][dplyr::filter()], [`mutate()`][dplyr::mutate()] and [`summarise()`][dplyr::summarise()]. +#' The `dplyr` package is not required for these functions to work, but these functions do support [variable grouping][dplyr::group_by()] and work conveniently inside `dplyr` verbs such as [`filter()`][dplyr::filter()], [`mutate()`][dplyr::mutate()] and [`summarise()`][dplyr::summarise()]. #' @return #' * [get_episode()]: a [double] vector #' * [is_new_episode()]: a [logical] vector @@ -85,8 +85,8 @@ #' n_episodes_30 = sum(is_new_episode(date, episode_days = 30))) #' #' -#' # grouping on patients and microorganisms leads to the same results -#' # as first_isolate(): +#' # grouping on patients and microorganisms leads to the same +#' # results as first_isolate() when using 'episode-based': #' x <- example_isolates %>% #' filter_first_isolate(include_unknown = TRUE, #' method = "episode-based") @@ -127,7 +127,7 @@ is_new_episode <- function(x, episode_days, ...) { } exec_episode <- function(type, x, episode_days, ...) { - x <- as.double(as.POSIXct(x)) # as.POSIXct() for Date classes + x <- as.double(as.POSIXct(x)) # as.POSIXct() required for Date classes # since x is now in seconds, get seconds from episode_days as well episode_seconds <- episode_days * 60 * 60 * 24 diff --git a/R/first_isolate.R b/R/first_isolate.R index fe5c2648..478a2412 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -25,7 +25,7 @@ #' Determine First (Weighted) Isolates #' -#' Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type. To determine patient episodes not necessarily based on microorganisms, use [is_new_episode()] that also supports grouping with the `dplyr` package. +#' Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type. These functions support all four methods as summarised by Hindler *et al.* in 2007 (\doi{10.1086/511864}). To determine patient episodes not necessarily based on microorganisms, use [is_new_episode()] that also supports grouping with the `dplyr` package. #' @inheritSection lifecycle Stable Lifecycle #' @param x a [data.frame] containing isolates. Can be left blank for automatic determination, see *Examples*. #' @param col_date column name of the result date (or date that is was received on the lab), defaults to the first column with a date class @@ -40,15 +40,15 @@ #' @param icu_exclude logical to indicate whether ICU isolates should be excluded (rows with value `TRUE` in the column set with `col_icu`) #' @param specimen_group value in the column set with `col_specimen` to filter on #' @param type type to determine weighed isolates; can be `"keyantimicrobials"` or `"points"`, see *Details* -#' @param method the algorithm to apply, either `"phenotype-based"`, `"episode-based"`, `"patient-based"` or `"isolate-based"` (can be abbreviated), see *Details* +#' @param method the method to apply, either `"phenotype-based"`, `"episode-based"`, `"patient-based"` or `"isolate-based"` (can be abbreviated), see *Details*. The default is `"phenotype-based"` if antimicrobial test results are present in the data, and `"episode-based"` otherwise. #' @param ignore_I logical to indicate whether antibiotic interpretations with `"I"` will be ignored when `type = "keyantimicrobials"`, see *Details* #' @param points_threshold minimum number of points to require before differences in the antibiogram will lead to inclusion of an isolate when `type = "points"`, see *Details* #' @param info a [logical] to indicate info should be printed, defaults to `TRUE` only in interactive mode #' @param include_unknown logical to indicate whether 'unknown' microorganisms should be included too, i.e. microbial code `"UNKNOWN"`, which defaults to `FALSE`. For WHONET users, this means that all records with organism code `"con"` (*contamination*) will be excluded at default. Isolates with a microbial ID of `NA` will always be excluded as first isolate. #' @param include_untested_rsi logical to indicate whether also rows without antibiotic results are still eligible for becoming a first isolate. Use `include_untested_rsi = FALSE` to always return `FALSE` for such rows. This checks the data set for columns of class `` and consequently requires transforming columns with antibiotic results using [as.rsi()] first. -#' @param ... arguments passed on to [first_isolate()] when using [filter_first_isolate()], or arguments passed on to [key_antimicrobials()] otherwise (such as `universal`, `gram_negative`, `gram_positive`) +#' @param ... arguments passed on to [first_isolate()] when using [filter_first_isolate()], otherwise arguments passed on to [key_antimicrobials()] (such as `universal`, `gram_negative`, `gram_positive`) #' @details -#' To conduct epidemiological analyses on antimicrobial resistance data, only so-called first isolates should be included to prevent overestimation and underestimation of antimicrobial resistance. Different algorithms can be used to do so, see below. +#' To conduct epidemiological analyses on antimicrobial resistance data, only so-called first isolates should be included to prevent overestimation and underestimation of antimicrobial resistance. Different methods can be used to do so, see below. #' #' These functions are context-aware. This means that then the `x` argument can be left blank, see *Examples*. #' @@ -56,51 +56,51 @@ #' #' All isolates with a microbial ID of `NA` will be excluded as first isolate. #' -#' ## Different algorithms +#' ## Different methods #' -#' According to Hindler *et al.* (2007, \doi{10.1086/511864}), there are different algorithms to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All algorithms select on a combination of the taxonomic genus and species (not subspecies). +#' According to Hindler *et al.* (2007, \doi{10.1086/511864}), there are different methods (algorithms) to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All methods select on a combination of the taxonomic genus and species (not subspecies). #' -#' All mentioned algorithms are covered in the [first_isolate()] function: +#' All mentioned methods are covered in the [first_isolate()] function: #' #' -#' | **Algorithm** | **Function to apply** | +#' | **Method** | **Function to apply** | #' |--------------------------------------------------|-------------------------------------------------------| -#' | Isolate-based | `first_isolate(x, method = "isolate-based")` | +#' | **Isolate-based** | `first_isolate(x, method = "isolate-based")` | #' | *(= all isolates)* | | #' | | | #' | | | -#' | Patient-based | `first_isolate(x, method = "patient-based")` | +#' | **Patient-based** | `first_isolate(x, method = "patient-based")` | #' | *(= first isolate per patient)* | | #' | | | #' | | | -#' | Episode-based | `first_isolate(x, method = "episode-based")`, or: | +#' | **Episode-based** | `first_isolate(x, method = "episode-based")`, or: | #' | *(= first isolate per episode)* | | #' | - 7-Day interval from initial isolate | - `first_isolate(x, method = "e", episode_days = 7)` | #' | - 30-Day interval from initial isolate | - `first_isolate(x, method = "e", episode_days = 30)` | #' | | | #' | | | -#' | Phenotype-based | `first_isolate(x, method = "phenotype-based")`, or: | +#' | **Phenotype-based** | `first_isolate(x, method = "phenotype-based")`, or: | #' | *(= first isolate per phenotype)* | | #' | - Major difference in any antimicrobial result | - `first_isolate(x, type = "points")` | #' | - Any difference in key antimicrobial results | - `first_isolate(x, type = "keyantimicrobials")` | #' #' ### Isolate-based #' -#' This algorithm does not require any selection, as all isolates should be included. It does, however, respect all arguments set in the [first_isolate()] function. For example, the default setting for `include_unknown` (`FALSE`) will omit selection of rows without a microbial ID. +#' This method does not require any selection, as all isolates should be included. It does, however, respect all arguments set in the [first_isolate()] function. For example, the default setting for `include_unknown` (`FALSE`) will omit selection of rows without a microbial ID. #' #' ### Patient-based #' -#' To include every genus-species combination per patient once, set the `episode_days` to `Inf`. Although often inappropriate, this algorithm makes sure that no duplicate isolates are selected from the same patient. +#' To include every genus-species combination per patient once, set the `episode_days` to `Inf`. Although often inappropriate, this method makes sure that no duplicate isolates are selected from the same patient. In a large longitudinal data set, this could mean that isolates are *excluded* that were found years after the initial isolate. #' #' ### Episode-based #' #' To include every genus-species combination per patient episode once, set the `episode_days` to a sensible number of days. Depending on the type of analysis, this could be 14, 30, 60 or 365. Short episodes are common for analysing specific hospital or ward data, long episodes are common for analysing regional and national data. #' -#' This is the most common algorithm to correct for duplicate isolates. Patients are categorised into episodes based on their ID and dates (e.g., the date of specimen receipt or laboratory result). While this is a common algorithm, it does not take into account antimicrobial test results. This means that e.g. a methicillin-resistant *Staphylococcus aureus* (MRSA) isolate cannot be differentiated from a wildtype *Staphylococcus aureus* isolate. +#' This is the most common method to correct for duplicate isolates. Patients are categorised into episodes based on their ID and dates (e.g., the date of specimen receipt or laboratory result). While this is a common method, it does not take into account antimicrobial test results. This means that e.g. a methicillin-resistant *Staphylococcus aureus* (MRSA) isolate cannot be differentiated from a wildtype *Staphylococcus aureus* isolate. #' #' ### Phenotype-based #' -#' This is a more reliable algorithm, since it also *weighs* the antibiogram (antimicrobial test results) yielding so-called 'first weighted isolates'. There are two different methods to weigh the antibiogram: +#' This is a more reliable method, since it also *weighs* the antibiogram (antimicrobial test results) yielding so-called 'first weighted isolates'. There are two different methods to weigh the antibiogram: #' #' 1. Using `type = "points"` and argument `points_threshold` #' @@ -116,14 +116,16 @@ #' Key antimicrobials are internally selected using the [key_antimicrobials()] function, but can also be added manually as a variable to the data and set in the `col_keyantimicrobials` argument. Another option is to pass the output of the [key_antimicrobials()] function directly to the `col_keyantimicrobials` argument. #' #' -#' The default algorithm is phenotype-based (using `type = "points"`) and episode-based (using `episode_days = 365`). This makes sure that every genus-species combination is selected per patient once per year, while taking into account all antimicrobial test results. +#' The default method is phenotype-based (using `type = "points"`) and episode-based (using `episode_days = 365`). This makes sure that every genus-species combination is selected per patient once per year, while taking into account all antimicrobial test results. If no antimicrobial test results are available in the data set, only the episode-based method is applied at default. #' @rdname first_isolate #' @seealso [key_antimicrobials()] #' @export #' @return A [`logical`] vector #' @source Methodology of this function is strictly based on: #' -#' **M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition**, 2014, *Clinical and Laboratory Standards Institute (CLSI)*. . +#' - **M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition**, 2014, *Clinical and Laboratory Standards Institute (CLSI)*. . +#' +#' - Hindler JF and Stelling J (2007). **Analysis and Presentation of Cumulative Antibiograms: A New Consensus Guideline from the Clinical and Laboratory Standards Institute.** Clinical Infectious Diseases, 44(6), 867–873. \doi{10.1086/511864} #' @inheritSection AMR Read more on Our Website! #' @examples #' # `example_isolates` is a data set available in the AMR package. @@ -142,11 +144,9 @@ #' example_isolates %>% #' filter(first_isolate()) #' -#' # short-hand versions: +#' # short-hand version: #' example_isolates %>% #' filter_first_isolate() -#' example_isolates %>% -#' filter_first_weighted_isolate() #' #' # grouped determination of first isolates (also prints group names): #' example_isolates %>% @@ -160,7 +160,7 @@ #' resistance = resistance(GEN)) # gentamicin resistance #' #' B <- example_isolates %>% -#' filter_first_weighted_isolate() %>% # the 1st isolate filter +#' filter_first_isolate() %>% # the 1st isolate filter #' group_by(hospital_id) %>% #' summarise(count = n_rsi(GEN), # gentamicin availability #' resistance = resistance(GEN)) # gentamicin resistance @@ -220,9 +220,7 @@ first_isolate <- function(x = NULL, meet_criteria(col_specimen, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) meet_criteria(col_icu, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) # method - if (missing(method)) { - method <- method[1L] - } + method <- coerce_method(method) meet_criteria(method, allow_class = "character", has_length = 1, is_in = c("phenotype-based", "episode-based", "patient-based", "isolate-based", "p", "e", "i")) # key antimicrobials if (length(col_keyantimicrobials) > 1) { @@ -233,7 +231,7 @@ first_isolate <- function(x = NULL, if (isFALSE(col_keyantimicrobials)) { col_keyantimicrobials <- NULL # method cannot be phenotype-based anymore - if (method %in% c("phenotype-based", "p")) { + if (method == "phenotype-based") { method <- "episode-based" } } @@ -250,10 +248,17 @@ first_isolate <- function(x = NULL, meet_criteria(include_unknown, allow_class = "logical", has_length = 1) meet_criteria(include_untested_rsi, allow_class = "logical", has_length = 1) - method[method == "p"] <- "phenotype-based" - method[method == "e"] <- "episode-based" - method[method == "i"] <- "isolate-based" - if (info == TRUE) { + # remove data.table, grouping from tibbles, etc. + x <- as.data.frame(x, stringsAsFactors = FALSE) + + any_col_contains_rsi <- any(vapply(FUN.VALUE = logical(1), + X = x, + FUN = function(x) any(as.character(x) %in% c("R", "S", "I"), na.rm = TRUE), + USE.NAMES = FALSE)) + if (method == "phenotype-based" & !any_col_contains_rsi) { + method <- "episode-based" + } + if (info == TRUE & message_not_thrown_before("first_isolate.method")) { message_(paste0("Determining first isolates using the '", font_bold(method), "' method", ifelse(method %in% c("episode-based", "phenotype-based"), ifelse(is.infinite(episode_days), @@ -262,11 +267,9 @@ first_isolate <- function(x = NULL, "")), as_note = FALSE, add_fn = font_black) + remember_thrown_message("first_isolate.method") } - # remove data.table, grouping from tibbles, etc. - x <- as.data.frame(x, stringsAsFactors = FALSE) - # try to find columns based on type # -- mo if (is.null(col_mo)) { @@ -360,10 +363,11 @@ first_isolate <- function(x = NULL, testcodes_exclude <- NULL } # remove testcodes - if (!is.null(testcodes_exclude) & info == TRUE) { + if (!is.null(testcodes_exclude) & info == TRUE & message_not_thrown_before("first_isolate.excludingtestcodes")) { message_("Excluding test codes: ", toString(paste0("'", testcodes_exclude, "'")), add_fn = font_black, as_note = FALSE) + remember_thrown_message("first_isolate.excludingtestcodes") } if (is.null(col_specimen)) { @@ -373,10 +377,11 @@ first_isolate <- function(x = NULL, # filter on specimen group and keyantibiotics when they are filled in if (!is.null(specimen_group)) { check_columns_existance(col_specimen, x) - if (info == TRUE) { + if (info == TRUE & message_not_thrown_before("first_isolate.excludingspecimen")) { message_("Excluding other than specimen group '", specimen_group, "'", add_fn = font_black, as_note = FALSE) + remember_thrown_message("first_isolate.excludingspecimen") } } if (!is.null(col_keyantimicrobials)) { @@ -449,18 +454,16 @@ first_isolate <- function(x = NULL, FALSE, TRUE) x$episode_group <- paste(x$newvar_patient_id, x$newvar_genus_species) - x$more_than_episode_ago <- unlist(lapply(unique(x$episode_group), - function(g, - df = x, - days = episode_days) { - is_new_episode(x = df[which(df$episode_group == g), ]$newvar_date, - episode_days = days) - })) + x$more_than_episode_ago <- unlist(lapply(split(x$newvar_date, + x$episode_group), + is_new_episode, + episode_days = episode_days), + use.names = FALSE) weighted.notice <- "" if (!is.null(col_keyantimicrobials)) { weighted.notice <- "weighted " - if (info == TRUE) { + if (info == TRUE & message_not_thrown_before("first_isolate.type")) { if (type == "keyantimicrobials") { message_("Basing inclusion on key antimicrobials, ", ifelse(ignore_I == FALSE, "not ", ""), @@ -474,6 +477,7 @@ first_isolate <- function(x = NULL, add_fn = font_black, as_note = FALSE) } + remember_thrown_message("first_isolate.type") } type_param <- type @@ -481,8 +485,7 @@ first_isolate <- function(x = NULL, z = pm_lag(x$newvar_key_ab), type = type_param, ignore_I = ignore_I, - points_threshold = points_threshold, - na.rm = TRUE) + points_threshold = points_threshold) # with key antibiotics x$newvar_first_isolate <- pm_if_else(x$newvar_row_index_sorted >= row.start & x$newvar_row_index_sorted <= row.end & @@ -540,7 +543,8 @@ first_isolate <- function(x = NULL, } }) message_("\nGroup: ", paste0(names(group), " = ", group, collapse = ", "), "\n", - as_note = FALSE) + as_note = FALSE, + add_fn = font_red) } } } @@ -608,7 +612,8 @@ filter_first_isolate <- function(x = NULL, col_date = NULL, col_patient_id = NULL, col_mo = NULL, - method = "episode-based", + episode_days = 365, + method = c("phenotype-based", "episode-based", "patient-based", "isolate-based"), ...) { if (is_null_or_grouped_tbl(x)) { # when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all()) @@ -619,39 +624,27 @@ filter_first_isolate <- function(x = NULL, meet_criteria(col_date, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) meet_criteria(col_patient_id, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) meet_criteria(col_mo, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) - meet_criteria(method, allow_class = "character", has_length = 1, is_in = c("phenotype-based", "episode-based", "patient-based", "isolate-based")) + meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = FALSE) + method <- coerce_method(method) + meet_criteria(method, allow_class = "character", has_length = 1, is_in = c("phenotype-based", "episode-based", "patient-based", "isolate-based", "p", "e", "i")) subset(x, first_isolate(x = x, col_date = col_date, col_patient_id = col_patient_id, col_mo = col_mo, + episode_days = episode_days, method = method, ...)) } -#' @rdname first_isolate -#' @export -filter_first_weighted_isolate <- function(x = NULL, - col_date = NULL, - col_patient_id = NULL, - col_mo = NULL, - method = "phenotype-based", - ...) { - if (is_null_or_grouped_tbl(x)) { - # when `x` is left blank, auto determine it (get_current_data() also contains dplyr::cur_data_all()) - # is also fix for using a grouped df as input (a dot as first argument) - x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x) +coerce_method <- function(method) { + if (is.null(method)) { + return(method) } - meet_criteria(x, allow_class = "data.frame") # also checks dimensions to be >0 - meet_criteria(col_date, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) - meet_criteria(col_patient_id, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) - meet_criteria(col_mo, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x)) - meet_criteria(method, allow_class = "character", has_length = 1, is_in = c("phenotype-based", "episode-based", "patient-based", "isolate-based")) - - subset(x, first_isolate(x = x, - col_date = col_date, - col_patient_id = col_patient_id, - col_mo = col_mo, - method = method, - ...)) + method <- tolower(as.character(method[1L])) + method[method %like% "^(p$|pheno)"] <- "phenotype-based" + method[method %like% "^(e$|episode)"] <- "episode-based" + method[method %like% "^patient"] <- "patient-based" + method[method %like% "^(i$|iso)"] <- "isolate-based" + method } diff --git a/R/ggplot_pca.R b/R/ggplot_pca.R index 9170048b..6cdb11a7 100755 --- a/R/ggplot_pca.R +++ b/R/ggplot_pca.R @@ -47,7 +47,7 @@ #' @param arrows_textangled a logical whether the text at the end of the arrows should be angled #' @param arrows_alpha the alpha (transparency) of the arrows and their text #' @param base_textsize the text size for all plot elements except the labels and arrows -#' @param ... Arguments passed on to functions +#' @param ... arguments passed on to functions #' @source The [ggplot_pca()] function is based on the `ggbiplot()` function from the `ggbiplot` package by Vince Vu, as found on GitHub: (retrieved: 2 March 2020, their latest commit: [`7325e88`](https://github.com/vqv/ggbiplot/commit/7325e880485bea4c07465a0304c470608fffb5d9); 12 February 2015). #' #' As per their GPL-2 licence that demands documentation of code changes, the changes made based on the source code were: diff --git a/R/join_microorganisms.R b/R/join_microorganisms.R index 015e47bf..c0418626 100755 --- a/R/join_microorganisms.R +++ b/R/join_microorganisms.R @@ -33,7 +33,7 @@ #' @param x existing table to join, or character vector #' @param by a variable to join by - if left empty will search for a column with class [`mo`] (created with [as.mo()]) or will be `"mo"` if that column name exists in `x`, could otherwise be a column name of `x` with values that exist in `microorganisms$mo` (such as `by = "bacteria_id"`), or another column in [microorganisms] (but then it should be named, like `by = c("bacteria_id" = "fullname")`) #' @param suffix if there are non-joined duplicate variables in `x` and `y`, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2. -#' @param ... ignored +#' @param ... ignored, only in place to allow future extensions #' @details **Note:** As opposed to the `join()` functions of `dplyr`, [character] vectors are supported and at default existing columns will get a suffix `"2"` and the newly joined columns will not get a suffix. #' #' If the `dplyr` package is installed, their join functions will be used. Otherwise, the much slower [merge()] function from base R will be used. diff --git a/R/key_antimicrobials.R b/R/key_antimicrobials.R index 206f2a5e..364f1d2c 100755 --- a/R/key_antimicrobials.R +++ b/R/key_antimicrobials.R @@ -35,7 +35,7 @@ #' @param gram_positive names of antibiotic agents for **Gram-negatives**, case-insensitive. Set to `NULL` to ignore. See *Details* for the default agents. #' @param antifungal names of antifungal agents for **fungi**, case-insensitive. Set to `NULL` to ignore. See *Details* for the default agents. #' @param only_rsi_columns a logical to indicate whether only columns must be included that were transformed to class `` (see [as.rsi()]) on beforehand (defaults to `FALSE`) -#' @param ... ignored, allows for future extensions +#' @param ... ignored, only in place to allow future extensions #' @details #' The [key_antimicrobials()] and [all_antimicrobials()] functions are context-aware. This means that then the `x` argument can be left blank, see *Examples*. #' @@ -264,14 +264,12 @@ generate_antimcrobials_string <- function(df) { } #' @rdname key_antimicrobials -#' @param info unused - previously used to indicate whether a progress bar should print #' @export antimicrobials_equal <- function(y, z, type = c("points", "keyantimicrobials"), ignore_I = TRUE, points_threshold = 2, - info = FALSE, ...) { meet_criteria(y, allow_class = "character") meet_criteria(z, allow_class = "character") @@ -279,7 +277,6 @@ antimicrobials_equal <- function(y, meet_criteria(type, allow_class = "character", has_length = 1, is_in = c("points", "keyantimicrobials")) meet_criteria(ignore_I, allow_class = "logical", has_length = 1) meet_criteria(points_threshold, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = TRUE) - meet_criteria(info, allow_class = "logical", has_length = 1) stop_ifnot(length(y) == length(z), "length of `y` and `z` must be equal") key2rsi <- function(val) { diff --git a/R/random.R b/R/random.R index 6917eb3b..60eda3ea 100644 --- a/R/random.R +++ b/R/random.R @@ -31,7 +31,7 @@ #' @param mo any character that can be coerced to a valid microorganism code with [as.mo()] #' @param ab any character that can be coerced to a valid antimicrobial agent code with [as.ab()] #' @param prob_RSI a vector of length 3: the probabilities for R (1st value), S (2nd value) and I (3rd value) -#' @param ... extension for future versions, not used at the moment +#' @param ... ignored, only in place to allow future extensions #' @details The base R function [sample()] is used for generating values. #' #' Generated values are based on the latest EUCAST guideline implemented in the [rsi_translation] data set. To create specific generated values per bug or drug, set the `mo` and/or `ab` argument. diff --git a/R/sysdata.rda b/R/sysdata.rda index 65b1bd30..620b47e5 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz index 3aeb6ccf..94f912ea 100644 Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ diff --git a/docs/404.html b/docs/404.html index c79d709e..75a4c03f 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.6.0.9012 + 1.6.0.9013 @@ -89,14 +89,14 @@