mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 01:22:25 +02:00
(v0.6.1.9053) prerelease fixes
This commit is contained in:
2
R/amr.R
2
R/amr.R
@ -45,7 +45,7 @@
|
||||
#' @section Authors:
|
||||
#' Matthijs S. Berends[1,2] Christian F. Luz[1], Erwin E.A. Hassing[2], Corinna Glasner[1], Alex W. Friedrich[1], Bhanu N.M. Sinha[1] \cr
|
||||
#'
|
||||
#' [1] Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - \url{rug.nl} \url{umcg.nl} \cr
|
||||
#' [1] Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - \url{https://www.rug.nl} \url{https://www.umcg.nl} \cr
|
||||
#' [2] Certe Medical Diagnostics & Advice, Groningen, the Netherlands - \url{certe.nl}
|
||||
|
||||
#' @section Read more on our website!:
|
||||
|
@ -40,7 +40,7 @@
|
||||
#'
|
||||
#' The Catalogue of Life (\url{http://www.catalogueoflife.org}) is the most comprehensive and authoritative global index of species currently available. It holds essential information on the names, relationships and distributions of over 1.6 million species. The Catalogue of Life is used to support the major biodiversity and conservation information services such as the Global Biodiversity Information Facility (GBIF), Encyclopedia of Life (EoL) and the International Union for Conservation of Nature Red List. It is recognised by the Convention on Biological Diversity as a significant component of the Global Taxonomy Initiative and a contribution to Target 1 of the Global Strategy for Plant Conservation.
|
||||
#'
|
||||
#' The syntax used to transform the original data to a cleansed R format, can be found here: \url{https://gitlab.com/msberends/AMR/blob/master/reproduction_of_microorganisms.R}.
|
||||
#' The syntax used to transform the original data to a cleansed R format, can be found here: \url{https://gitlab.com/msberends/AMR/blob/master/data-raw/reproduction_of_microorganisms.R}.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @name catalogue_of_life
|
||||
#' @rdname catalogue_of_life
|
||||
|
15
R/data.R
15
R/data.R
@ -59,16 +59,9 @@
|
||||
#' \describe{
|
||||
#' \item{\code{mo}}{ID of microorganism as used by this package}
|
||||
#' \item{\code{col_id}}{Catalogue of Life ID}
|
||||
#' \item{\code{fullname}}{Full name, like \code{"Echerichia coli"}}
|
||||
#' \item{\code{kingdom}}{Taxonomic kingdom of the microorganism}
|
||||
#' \item{\code{phylum}}{Taxonomic phylum of the microorganism}
|
||||
#' \item{\code{class}}{Taxonomic class of the microorganism}
|
||||
#' \item{\code{order}}{Taxonomic order of the microorganism}
|
||||
#' \item{\code{family}}{Taxonomic family of the microorganism}
|
||||
#' \item{\code{genus}}{Taxonomic genus of the microorganism}
|
||||
#' \item{\code{species}}{Taxonomic species of the microorganism}
|
||||
#' \item{\code{subspecies}}{Taxonomic subspecies of the microorganism}
|
||||
#' \item{\code{rank}}{Taxonomic rank of the microorganism, like \code{"species"} or \code{"genus"}}
|
||||
#' \item{\code{fullname}}{Full name, like \code{"Escherichia coli"}}
|
||||
#' \item{\code{kingdom}, \code{phylum}, \code{class}, \code{order}, \code{family}, \code{genus}, \code{species}, \code{subspecies}}{Taxonomic rank of the microorganism}
|
||||
#' \item{\code{rank}}{Text of the taxonomic rank of the microorganism, like \code{"species"} or \code{"genus"}}
|
||||
#' \item{\code{ref}}{Author(s) and year of concerning scientific publication}
|
||||
#' \item{\code{species_id}}{ID of the species as used by the Catalogue of Life}
|
||||
#' \item{\code{source}}{Either \code{"CoL"}, \code{"DSMZ"} (see source) or "manually added"}
|
||||
@ -119,7 +112,7 @@ catalogue_of_life <- list(
|
||||
#' Translation table for microorganism codes
|
||||
#'
|
||||
#' A data set containing commonly used codes for microorganisms, from laboratory systems and WHONET. Define your own with \code{\link{set_mo_source}}.
|
||||
#' @format A \code{\link{data.frame}} with 5,171 observations and 2 variables:
|
||||
#' @format A \code{\link{data.frame}} with 4,969 observations and 2 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{certe}}{Commonly used code of a microorganism}
|
||||
#' \item{\code{mo}}{ID of the microorganism in the \code{\link{microorganisms}} data set}
|
||||
|
13
R/freq.R
13
R/freq.R
@ -342,7 +342,7 @@ freq <- function(x,
|
||||
# mult.columns <- 2
|
||||
} else {
|
||||
x.name <- deparse(substitute(x))
|
||||
if (x.name %like% "[$]") {
|
||||
if (all(x.name %like% "[$]") & length(x.name) == 1) {
|
||||
cols <- unlist(strsplit(x.name, "$", fixed = TRUE))[2]
|
||||
x.name <- unlist(strsplit(x.name, "$", fixed = TRUE))[1]
|
||||
# try to find the object to determine dimensions
|
||||
@ -710,7 +710,8 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ",
|
||||
})
|
||||
|
||||
# numeric values
|
||||
if (has_length == TRUE & any(x_class %in% c("double", "integer", "numeric", "raw", "single"))) {
|
||||
if (has_length == TRUE & !is.null(header$sd)) {
|
||||
# any(x_class %in% c("double", "integer", "numeric", "raw", "single"))) {
|
||||
header$sd <- paste0(header$sd, " (CV: ", header$cv, ", MAD: ", header$mad, ")")
|
||||
header$fivenum <- paste0(paste(trimws(header$fivenum), collapse = " | "), " (IQR: ", header$IQR, ", CQV: ", header$cqv, ")")
|
||||
header$outliers_total <- paste0(header$outliers_total, " (unique count: ", header$outliers_unique, ")")
|
||||
@ -1018,9 +1019,11 @@ print.freq <- function(x,
|
||||
} else {
|
||||
opt$column_names <- opt$column_names[!opt$column_names == "Item"]
|
||||
}
|
||||
|
||||
all_unique <- FALSE
|
||||
if ("count" %in% colnames(x)) {
|
||||
if (all(x$count == 1)) {
|
||||
warning("All observations are unique.", call. = FALSE)
|
||||
all_unique <- TRUE
|
||||
}
|
||||
x$count <- format(x$count, decimal.mark = opt$decimal.mark, big.mark = opt$big.mark)
|
||||
} else {
|
||||
@ -1072,6 +1075,10 @@ print.freq <- function(x,
|
||||
cat("\n")
|
||||
}
|
||||
|
||||
if (all_unique == TRUE) {
|
||||
message("NOTE: All observations are unique.")
|
||||
}
|
||||
|
||||
# reset old kable setting
|
||||
options(knitr.kable.NA = opt.old)
|
||||
return(invisible())
|
||||
|
29
R/mo.R
29
R/mo.R
@ -195,10 +195,11 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE,
|
||||
# check onLoad() in R/zzz.R: data tables are created there.
|
||||
}
|
||||
|
||||
x[x == ""] <- NA_character_
|
||||
# WHONET: xxx = no growth
|
||||
x[tolower(as.character(paste0(x, ""))) %in% c("", "xxx", "na", "nan")] <- NA_character_
|
||||
|
||||
uncertainty_level <- translate_allow_uncertain(allow_uncertain)
|
||||
mo_hist <- get_mo_history(x, uncertainty_level, force = isTRUE(list(...)$force_mo_history))
|
||||
# mo_hist <- get_mo_history(x, uncertainty_level, force = isTRUE(list(...)$force_mo_history))
|
||||
|
||||
if (mo_source_isvalid(reference_df)
|
||||
& isFALSE(Becker)
|
||||
@ -231,11 +232,11 @@ as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE,
|
||||
& isFALSE(Lancefield)) {
|
||||
y <- x
|
||||
|
||||
} else if (!any(is.na(mo_hist))
|
||||
& isFALSE(Becker)
|
||||
& isFALSE(Lancefield)) {
|
||||
# check previously found results
|
||||
y <- mo_hist
|
||||
# } else if (!any(is.na(mo_hist))
|
||||
# & isFALSE(Becker)
|
||||
# & isFALSE(Lancefield)) {
|
||||
# # check previously found results
|
||||
# y <- mo_hist
|
||||
|
||||
} else if (all(tolower(x) %in% microorganismsDT$fullname_lower)
|
||||
& isFALSE(Becker)
|
||||
@ -299,7 +300,8 @@ exec_as.mo <- function(x,
|
||||
# check onLoad() in R/zzz.R: data tables are created there.
|
||||
}
|
||||
|
||||
x[x == ""] <- NA_character_
|
||||
# WHONET: xxx = no growth
|
||||
x[tolower(as.character(paste0(x, ""))) %in% c("", "xxx", "na", "nan")] <- NA_character_
|
||||
|
||||
if (initial_search == TRUE) {
|
||||
options(mo_failures = NULL)
|
||||
@ -340,12 +342,11 @@ exec_as.mo <- function(x,
|
||||
# only check the uniques, which is way faster
|
||||
x <- unique(x)
|
||||
# remove empty values (to later fill them in again with NAs)
|
||||
# ("xxx" is WHONET code for 'no growth' and "con" is WHONET code for 'contamination')
|
||||
# ("xxx" is WHONET code for 'no growth')
|
||||
x <- x[!is.na(x)
|
||||
& !is.null(x)
|
||||
& !identical(x, "")
|
||||
& !identical(x, "xxx")
|
||||
& !identical(x, "con")]
|
||||
& !identical(x, "xxx")]
|
||||
|
||||
# conversion of old MO codes from v0.5.0 (ITIS) to later versions (Catalogue of Life)
|
||||
if (any(x %like% "^[BFP]_[A-Z]{3,7}") & !all(x %in% microorganisms$mo)) {
|
||||
@ -560,7 +561,8 @@ exec_as.mo <- function(x,
|
||||
next
|
||||
}
|
||||
|
||||
if (any(tolower(x_backup_without_spp[i]) %in% c(NA, "", "xxx", "con", "na", "nan"))) {
|
||||
# WHONET: xxx = no growth
|
||||
if (tolower(as.character(paste0(x_backup_without_spp[i], ""))) %in% c("", "xxx", "na", "nan")) {
|
||||
x[i] <- NA_character_
|
||||
next
|
||||
}
|
||||
@ -1273,8 +1275,7 @@ exec_as.mo <- function(x,
|
||||
x_input_unique_nonempty <- unique(x_input[!is.na(x_input)
|
||||
& !is.null(x_input)
|
||||
& !identical(x_input, "")
|
||||
& !identical(x_input, "xxx")
|
||||
& !identical(x_input, "con")])
|
||||
& !identical(x_input, "xxx")])
|
||||
|
||||
# left join the found results to the original input values (x_input)
|
||||
df_found <- data.frame(input = as.character(x_input_unique_nonempty),
|
||||
|
Reference in New Issue
Block a user