diff --git a/DESCRIPTION b/DESCRIPTION index 76a7bc83..a9dd97d9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.1.0.9018 -Date: 2020-05-22 +Version: 1.1.0.9019 +Date: 2020-05-25 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index be5d3b54..c1eb90b1 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 1.1.0.9018 -## Last updated: 22-May-2020 +# AMR 1.1.0.9019 +## Last updated: 25-May-2020 ### Breaking * Removed code dependency on all other R packages, making this package fully independent of the development process of others. This is a major code change, but will probably not be noticeable by most users. @@ -20,7 +20,8 @@ * Improvements for algorithm in `as.ab()`, so that e.g. `as.ab("ampi sul")` and `ab_name("ampi sul")` work * Functions `ab_atc()` and `ab_group()` now return `NA` if no antimicrobial agent could be found * Small fix for some text input that could not be coerced as valid MIC values -* Fixed interpretation of generic CLSI interpretation rules (thanks to Anthony Underwood) +* Fix for interpretation of generic CLSI interpretation rules (thanks to Anthony Underwood) +* Fix for `set_mo_source()` to make sure that column `mo` will always be the second column ### Other * Removed previously deprecated function `p.symbol()` - it was replaced with `p_symbol()` diff --git a/R/ab_property.R b/R/ab_property.R index a51fa8be..3a021818 100644 --- a/R/ab_property.R +++ b/R/ab_property.R @@ -22,7 +22,7 @@ #' Property of an antibiotic #' #' Use these functions to return a specific property of an antibiotic from the [antibiotics] data set. All input values will be evaluated internally with [as.ab()]. -#' @inheritSection lifecycle Maturing lifecycle +#' @inheritSection lifecycle Stable lifecycle #' @param x any (vector of) text that can be coerced to a valid microorganism code with [as.ab()] #' @param tolower logical to indicate whether the first character of every output should be transformed to a lower case character. This will lead to e.g. "polymyxin B" and not "polymyxin b". #' @param property one of the column names of one of the [antibiotics] data set @@ -33,7 +33,7 @@ #' @param ... other parameters passed on to [as.ab()] #' @details All output will be [translate]d where possible. #' -#' The function [ab_url()] will return the direct URL to the official WHO website. A warning will be returned if the reauired ATC code is not available. +#' The function [ab_url()] will return the direct URL to the official WHO website. A warning will be returned if the required ATC code is not available. #' @inheritSection as.ab Source #' @rdname ab_property #' @name ab_property diff --git a/R/mo_property.R b/R/mo_property.R index c6409fdf..40a08dca 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -22,6 +22,7 @@ #' Property of a microorganism #' #' Use these functions to return a specific property of a microorganism. All input values will be evaluated internally with [as.mo()], which makes it possible to use microbial abbreviations, codes and names as input. Please see *Examples*. +#' @inheritSection lifecycle Stable lifecycle #' @param x any (vector of) text that can be coerced to a valid microorganism code with [as.mo()] #' @param property one of the column names of the [microorganisms] data set or `"shortname"` #' @param language language of the returned text, defaults to system language (see [get_locale()]) and can also be set with `getOption("AMR_locale")`. Use `language = NULL` or `language = ""` to prevent translation. diff --git a/R/mo_source.R b/R/mo_source.R index b44b79d4..611b7524 100644 --- a/R/mo_source.R +++ b/R/mo_source.R @@ -19,13 +19,13 @@ # Visit our website for more info: https://msberends.gitlab.io/AMR. # # ==================================================================== # -#' Use predefined reference data set +#' User-defined reference data set for microorganisms #' #' @description These functions can be used to predefine your own reference to be used in [as.mo()] and consequently all `mo_*` functions like [mo_genus()] and [mo_gramstain()]. #' #' This is **the fastest way** to have your organisation (or analysis) specific codes picked up and translated by this package. #' @inheritSection lifecycle Stable lifecycle -#' @param path location of your reference file, see Details +#' @param path location of your reference file, see Details. Can be `""`, `NULL` or `FALSE` to delete the reference file. #' @rdname mo_source #' @name mo_source #' @aliases set_mo_source get_mo_source @@ -35,11 +35,12 @@ #' #' [get_mo_source()] will return the data set by reading `"~/.mo_source.rds"` with [readRDS()]. If the original file has changed (the file defined with `path`), it will call [set_mo_source()] to update the data file automatically. #' -#' Reading an Excel file (`.xlsx`) with only one row has a size of 8-9 kB. The compressed file used by this package will have a size of 0.1 kB and can be read by [get_mo_source()] in only a couple of microseconds (a millionth of a second). +#' Reading an Excel file (`.xlsx`) with only one row has a size of 8-9 kB. The compressed file created with [set_mo_source()] will then have a size of 0.1 kB and can be read by [get_mo_source()] in only a couple of microseconds (millionths of a second). #' -#' ## How it works +#' @section How to setup: +#' +#' Imagine this data on a sheet of an Excel file (mo codes were looked up in the [microorganisms] data set). The first column contains the organisation specific codes, the second column contains an MO code from this package: #' -#' Imagine this data on a sheet of an Excel file (mo codes were looked up in the `microorganisms` data set). The first column contains the organisation specific codes, the second column contains an MO code from this package: #' ``` #' | A | B | #' --|--------------------|--------------| @@ -50,27 +51,31 @@ #' ``` #' #' We save it as `"home/me/ourcodes.xlsx"`. Now we have to set it as a source: +#' #' ``` #' set_mo_source("home/me/ourcodes.xlsx") -#' # Created mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. +#' #> NOTE: Created mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx' +#' #> (columns "Organisation XYZ" and "mo") #' ``` #' -#' It has now created a file `"~/.mo_source.rds"` with the contents of our Excel file, but only the first column with foreign values and the 'mo' column will be kept. +#' It has now created a file `"~/.mo_source.rds"` with the contents of our Excel file. Only the first column with foreign values and the 'mo' column will be kept when creating the RDS file. #' #' And now we can use it in our functions: +#' #' ``` #' as.mo("lab_mo_ecoli") -#' [1] B_ESCHR_COLI +#' #> [1] B_ESCHR_COLI #' #' mo_genus("lab_mo_kpneumoniae") -#' [1] "Klebsiella" +#' #> [1] "Klebsiella" #' #' # other input values still work too #' as.mo(c("Escherichia coli", "E. coli", "lab_mo_ecoli")) -#' [1] B_ESCHR_COLI B_ESCHR_COLI B_ESCHR_COLI +#' #> [1] B_ESCHR_COLI B_ESCHR_COLI B_ESCHR_COLI #' ``` #' -#' If we edit the Excel file to, let's say, by adding row 4 like this: +#' If we edit the Excel file by, let's say, adding row 4 like this: +#' #' ``` #' | A | B | #' --|--------------------|--------------| @@ -82,36 +87,41 @@ #' ``` #' #' ...any new usage of an MO function in this package will update your data file: +#' #' ``` #' as.mo("lab_mo_ecoli") -#' # Updated mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'. -#' [1] B_ESCHR_COLI +#' #> NOTE: Updated mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx' +#' #> (columns "Organisation XYZ" and "mo") +#' #> [1] B_ESCHR_COLI #' #' mo_genus("lab_Staph_aureus") -#' [1] "Staphylococcus" +#' #> [1] "Staphylococcus" #' ``` #' -#' To remove the reference data file completely, just use `""` or `NULL` as input for `[set_mo_source()]`: +#' To delete the reference data file, just use `""`, `NULL` or `FALSE` as input for [set_mo_source()]: +#' #' ``` #' set_mo_source(NULL) #' # Removed mo_source file '~/.mo_source.rds'. #' ``` +#' +#' If the original Excel file is moved or deleted, the mo_source file will be removed upon the next use of [as.mo()]. If the mo_source file is manually deleted (i.e. without using [set_mo_source()]), the references to the mo_source file will be removed upon the next use of [as.mo()]. #' @export #' @inheritSection AMR Read more on our website! set_mo_source <- function(path) { file_location <- path.expand("~/mo_source.rds") - if (!is.character(path) | length(path) > 1) { - stop("`path` must be a character of length 1.") + if (length(path) > 1) { + stop("`path` must be of length 1.") } - if (path %in% c(NULL, "")) { + if (is.null(path) || path %in% c(FALSE, "")) { options(mo_source = NULL) options(mo_source_timestamp = NULL) if (file.exists(file_location)) { unlink(file_location) - message("Removed mo_source file '", file_location, "'.") + message(font_red(paste0("Removed mo_source file '", font_bold(file_location), "'"))) } return(invisible()) } @@ -154,13 +164,13 @@ set_mo_source <- function(path) { # check integrity mo_source_isvalid(df) - df <- df %>% filter(!is.na(mo)) + df <- subset(df, !is.na(mo)) # keep only first two columns, second must be mo if (colnames(df)[1] == "mo") { - df <- df[, c(2, 1)] + df <- df[, c(colnames(df)[2], "mo")] } else { - df <- df[, c(1, 2)] + df <- df[, c(colnames(df)[1], "mo")] } df <- as.data.frame(df, stringAsFactors = FALSE) @@ -174,30 +184,40 @@ set_mo_source <- function(path) { saveRDS(df, file_location) options(mo_source = path) options(mo_source_timestamp = as.character(file.info(path)$mtime)) - message(action, " mo_source file '", file_location, "' from '", path, "'.") + message(font_blue(paste0("NOTE: ", + action, " mo_source file '", font_bold(file_location), "'", + " from '", font_bold(path), "'", + '\n (columns "', colnames(df)[1], '" and "', colnames(df)[2], '")'))) } #' @rdname mo_source #' @export get_mo_source <- function() { if (is.null(getOption("mo_source", NULL))) { - NULL - } else { - old_time <- as.POSIXct(getOption("mo_source_timestamp")) - new_time <- as.POSIXct(as.character(file.info(getOption("mo_source", ""))$mtime)) - - if (is.na(new_time)) { - # source file was deleted, remove reference too - set_mo_source("") - return(NULL) - } - if (new_time != old_time) { - # set updated source - set_mo_source(getOption("mo_source")) - } - file_location <- path.expand("~/mo_source.rds") - readRDS(file_location) + return(NULL) } + + if (!file.exists(path.expand("~/mo_source.rds"))) { + options(mo_source = NULL) + options(mo_source_timestamp = NULL) + message(font_blue("NOTE: Removed references to deleted mo_source file (see ?mo_source)")) + return(NULL) + } + + old_time <- as.POSIXct(getOption("mo_source_timestamp")) + new_time <- as.POSIXct(as.character(file.info(getOption("mo_source", ""))$mtime)) + + if (is.na(new_time)) { + # source file was deleted, remove reference too + set_mo_source("") + return(NULL) + } + if (new_time != old_time) { + # set updated source + set_mo_source(getOption("mo_source")) + } + file_location <- path.expand("~/mo_source.rds") + readRDS(file_location) } mo_source_isvalid <- function(x, refer_to_name = "`reference_df`", stop_on_error = TRUE) { diff --git a/docs/404.html b/docs/404.html index 9a2803fa..322b2c22 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 2c558f42..4ceeb702 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index fd2e26e5..1d459a7a 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -39,7 +39,7 @@ @@ -186,7 +186,7 @@vignettes/AMR.Rmd
AMR.Rmd
Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 20 May 2020.
+Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 25 May 2020.
Now, let’s start the cleaning and the analysis!
@@ -432,16 +432,16 @@ Longest: 1