mirror of
https://github.com/msberends/AMR.git
synced 2024-12-26 06:06:12 +01:00
custom ab fix
This commit is contained in:
parent
85ed7ea5f0
commit
ad68b50ecd
@ -1,6 +1,6 @@
|
|||||||
Package: AMR
|
Package: AMR
|
||||||
Version: 1.8.2.9016
|
Version: 1.8.2.9018
|
||||||
Date: 2022-10-14
|
Date: 2022-10-15
|
||||||
Title: Antimicrobial Resistance Data Analysis
|
Title: Antimicrobial Resistance Data Analysis
|
||||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||||
data analysis and to work with microbial and antimicrobial properties by
|
data analysis and to work with microbial and antimicrobial properties by
|
||||||
|
2
NEWS.md
2
NEWS.md
@ -1,4 +1,4 @@
|
|||||||
# AMR 1.8.2.9016
|
# AMR 1.8.2.9018
|
||||||
|
|
||||||
This version will eventually become v2.0! We're happy to reach a new major milestone soon!
|
This version will eventually become v2.0! We're happy to reach a new major milestone soon!
|
||||||
|
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
#' @rdname add_custom_antimicrobials
|
#' @rdname add_custom_antimicrobials
|
||||||
#' @export
|
#' @export
|
||||||
#' @examples
|
#' @examples
|
||||||
|
#' \donttest{
|
||||||
|
#'
|
||||||
#' # returns NA and throws a warning (which is now suppressed):
|
#' # returns NA and throws a warning (which is now suppressed):
|
||||||
#' suppressWarnings(
|
#' suppressWarnings(
|
||||||
#' as.ab("test")
|
#' as.ab("test")
|
||||||
@ -90,6 +92,7 @@
|
|||||||
#' ampicillin = as.rsi("R"))
|
#' ampicillin = as.rsi("R"))
|
||||||
#' x
|
#' x
|
||||||
#' x[, betalactams()]
|
#' x[, betalactams()]
|
||||||
|
#' }
|
||||||
add_custom_antimicrobials <- function(x) {
|
add_custom_antimicrobials <- function(x) {
|
||||||
meet_criteria(x, allow_class = "data.frame")
|
meet_criteria(x, allow_class = "data.frame")
|
||||||
stop_ifnot(all(c("ab", "name") %in% colnames(x)),
|
stop_ifnot(all(c("ab", "name") %in% colnames(x)),
|
||||||
@ -107,10 +110,22 @@ add_custom_antimicrobials <- function(x) {
|
|||||||
x$loinc <- as.list(x$loinc)
|
x$loinc <- as.list(x$loinc)
|
||||||
}
|
}
|
||||||
AMR_env$custom_ab_codes <- c(AMR_env$custom_ab_codes, x$ab)
|
AMR_env$custom_ab_codes <- c(AMR_env$custom_ab_codes, x$ab)
|
||||||
|
class(AMR_env$AB_lookup$ab) <- "character"
|
||||||
|
|
||||||
bind_rows <- import_fn("bind_rows", "dplyr", error_on_fail = TRUE)
|
bind_rows <- import_fn("bind_rowtts", "dplyr", error_on_fail = FALSE)
|
||||||
AMR_env$AB_lookup <- unique(bind_rows(AMR_env$AB_lookup, x))
|
if (is.null(bind_rows)) {
|
||||||
|
# do the binding in base R
|
||||||
|
new_df <- AMR_env$AB_lookup[0, , drop = FALSE][seq_len(NROW(x)), , drop = FALSE]
|
||||||
|
rownames(new_df) <- NULL
|
||||||
|
for (col in colnames(x)) {
|
||||||
|
new_df[, col] <- x[, col, drop = TRUE]
|
||||||
|
}
|
||||||
|
AMR_env$AB_lookup <- unique(rbind(AMR_env$AB_lookup, new_df))
|
||||||
|
} else {
|
||||||
|
# otherwise use dplyr
|
||||||
|
AMR_env$AB_lookup <- unique(bind_rows(AMR_env$AB_lookup, x))
|
||||||
|
}
|
||||||
|
class(AMR_env$AB_lookup$ab) <- c("ab", "character")
|
||||||
message_("Added ", nr2char(nrow(x)), " record", ifelse(nrow(x) > 1, "s", ""), " to the internal `antibiotics` data set.")
|
message_("Added ", nr2char(nrow(x)), " record", ifelse(nrow(x) > 1, "s", ""), " to the internal `antibiotics` data set.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ add_custom_antimicrobials(
|
|||||||
Use \code{\link[=clear_custom_antimicrobials]{clear_custom_antimicrobials()}} to clear the previously added antimicrobials.
|
Use \code{\link[=clear_custom_antimicrobials]{clear_custom_antimicrobials()}} to clear the previously added antimicrobials.
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
|
\donttest{
|
||||||
|
|
||||||
# returns NA and throws a warning (which is now suppressed):
|
# returns NA and throws a warning (which is now suppressed):
|
||||||
suppressWarnings(
|
suppressWarnings(
|
||||||
as.ab("test")
|
as.ab("test")
|
||||||
@ -74,3 +76,4 @@ x <- data.frame(random_column = "test",
|
|||||||
x
|
x
|
||||||
x[, betalactams()]
|
x[, betalactams()]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user