1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-25 19:26:13 +01:00

(v1.8.1.9003) set_mo_source() fix

This commit is contained in:
dr. M.S. (Matthijs) Berends 2022-05-09 20:36:44 +02:00
parent 152db9d1b5
commit 1c891cc90c
15 changed files with 86 additions and 76 deletions

View File

@ -1,5 +1,5 @@
Package: AMR
Version: 1.8.1.9002
Version: 1.8.1.9003
Date: 2022-05-09
Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR)

View File

@ -1,10 +1,11 @@
# `AMR` 1.8.1.9002
# `AMR` 1.8.1.9003
## <small>Last updated: 9 May 2022</small>
### Changed
* Removed `as.integer()` for MIC values, since MIC are not integer values and running `table()` on MIC values will consequently fail for not being able to retrieve the level position (as that's how normally `as.integer()` on `factor`s work)
* Removed `as.integer()` for MIC values, since MIC are not integer values and running `table()` on MIC values consequently failed for not being able to retrieve the level position (as that's how normally `as.integer()` on `factor`s work)
* `droplevels()` on MIC will now return a common `factor` at default and will lose the `<mic>` class. Use `droplevels(..., as.mic = TRUE)` to keep the `<mic>` class.
* Small fix for using `ab_from_text()`
* Fixes for reading in text files using `set_mo_source()`, which now also allows the source file to contain valid taxonomic names instead of only valid microorganism ID of this package
# `AMR` 1.8.1

View File

@ -29,16 +29,16 @@
#'
#' This is **the fastest way** to have your organisation (or analysis) specific codes picked up and translated by this package, since you don't have to bother about it again after setting it up once.
#' @inheritSection lifecycle Stable Lifecycle
#' @param path location of your reference file, see *Details*. Can be `""`, `NULL` or `FALSE` to delete the reference file.
#' @param path location of your reference file, this can be any text file (comma-, tab- or pipe-separated) or an Excel file (see *Details*). Can also be `""`, `NULL` or `FALSE` to delete the reference file.
#' @param destination destination of the compressed data file, default to the user's home directory.
#' @rdname mo_source
#' @name mo_source
#' @aliases set_mo_source get_mo_source
#' @details The reference file can be a text file separated with commas (CSV) or tabs or pipes, an Excel file (either 'xls' or 'xlsx' format) or an \R object file (extension '.rds'). To use an Excel file, you will need to have the `readxl` package installed.
#'
#' [set_mo_source()] will check the file for validity: it must be a [data.frame], must have a column named `"mo"` which contains values from [`microorganisms$mo`][microorganisms] and must have a reference column with your own defined values. If all tests pass, [set_mo_source()] will read the file into \R and will ask to export it to `"~/mo_source.rds"`. The CRAN policy disallows packages to write to the file system, although '*exceptions may be allowed in interactive sessions if the package obtains confirmation from the user*'. For this reason, this function only works in interactive sessions so that the user can **specifically confirm and allow** that this file will be created. The destination of this file can be set with the `destination` argument and defaults to the user's home directory. It can also be set as an \R option, using `options(AMR_mo_source = "my/location/file.rds")`.
#' [set_mo_source()] will check the file for validity: it must be a [data.frame], must have a column named `"mo"` which contains values from [`microorganisms$mo`][microorganisms] or [`microorganisms$fullname`][microorganisms] and must have a reference column with your own defined values. If all tests pass, [set_mo_source()] will read the file into \R and will ask to export it to `"~/mo_source.rds"`. The CRAN policy disallows packages to write to the file system, although '*exceptions may be allowed in interactive sessions if the package obtains confirmation from the user*'. For this reason, this function only works in interactive sessions so that the user can **specifically confirm and allow** that this file will be created. The destination of this file can be set with the `destination` argument and defaults to the user's home directory. It can also be set as an \R option, using `options(AMR_mo_source = "my/location/file.rds")`.
#'
#' The created compressed data file `"mo_source.rds"` will be used at default for MO determination (function [as.mo()] and consequently all `mo_*` functions like [mo_genus()] and [mo_gramstain()]). The location and timestamp of the original file will be saved as an attribute to the compressed data file.
#' The created compressed data file `"mo_source.rds"` will be used at default for MO determination (function [as.mo()] and consequently all `mo_*` functions like [mo_genus()] and [mo_gramstain()]). The location and timestamp of the original file will be saved as an [attribute][base::attributes()] to the compressed data file.
#'
#' The function [get_mo_source()] will return the data set by reading `"mo_source.rds"` with [readRDS()]. If the original file has changed (by checking the location and timestamp of the original file), it will call [set_mo_source()] to update the data file automatically if used in an interactive session.
#'
@ -46,14 +46,14 @@
#'
#' @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. The first column contains the organisation specific codes, the second column contains valid taxonomic names:
#'
#' ```
#' | A | B |
#' --|--------------------|--------------|
#' --|--------------------|-----------------------|
#' 1 | Organisation XYZ | mo |
#' 2 | lab_mo_ecoli | B_ESCHR_COLI |
#' 3 | lab_mo_kpneumoniae | B_KLBSL_PNMN |
#' 2 | lab_mo_ecoli | Escherichia coli |
#' 3 | lab_mo_kpneumoniae | Klebsiella pneumoniae |
#' 4 | | |
#' ```
#'
@ -90,11 +90,11 @@
#'
#' ```
#' | A | B |
#' --|--------------------|--------------|
#' --|--------------------|-----------------------|
#' 1 | Organisation XYZ | mo |
#' 2 | lab_mo_ecoli | B_ESCHR_COLI |
#' 3 | lab_mo_kpneumoniae | B_KLBSL_PNMN |
#' 4 | lab_Staph_aureus | B_STPHY_AURS |
#' 2 | lab_mo_ecoli | Escherichia coli |
#' 3 | lab_mo_kpneumoniae | Klebsiella pneumoniae |
#' 4 | lab_Staph_aureus | Staphylococcus aureus |
#' 5 | | |
#' ```
#'
@ -144,6 +144,7 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s
stop_ifnot(file.exists(path), "file not found: ", path)
df <- NULL
if (path %like% "[.]rds$") {
df <- readRDS(path)
@ -153,28 +154,34 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s
df <- readxl::read_excel(path)
} else if (path %like% "[.]tsv$") {
df <- utils::read.table(header = TRUE, sep = "\t", stringsAsFactors = FALSE)
df <- utils::read.table(file = path, header = TRUE, sep = "\t", stringsAsFactors = FALSE)
} else if (path %like% "[.]csv$") {
df <- utils::read.table(file = path, header = TRUE, sep = ",", stringsAsFactors = FALSE)
} else {
# try comma first
try(
df <- utils::read.table(header = TRUE, sep = ",", stringsAsFactors = FALSE),
df <- utils::read.table(file = path, header = TRUE, sep = ",", stringsAsFactors = FALSE),
silent = TRUE)
if (!check_validity_mo_source(df, stop_on_error = FALSE)) {
# try tab
try(
df <- utils::read.table(header = TRUE, sep = "\t", stringsAsFactors = FALSE),
df <- utils::read.table(file = path, header = TRUE, sep = "\t", stringsAsFactors = FALSE),
silent = TRUE)
}
if (!check_validity_mo_source(df, stop_on_error = FALSE)) {
# try pipe
try(
df <- utils::read.table(header = TRUE, sep = "|", stringsAsFactors = FALSE),
df <- utils::read.table(file = path, header = TRUE, sep = "|", stringsAsFactors = FALSE),
silent = TRUE)
}
}
# check integrity
if (is.null(df)) {
stop_("the path '", path, "' could not be imported as a dataset.")
}
check_validity_mo_source(df)
df <- subset(df, !is.na(mo))
@ -187,7 +194,7 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s
}
df <- as.data.frame(df, stringAsFactors = FALSE)
df[, "mo"] <- set_clean_class(df[, "mo", drop = TRUE], c("mo", "character"))
df[, "mo"] <- as.mo(df[, "mo", drop = TRUE])
# success
if (file.exists(mo_source_destination)) {
@ -275,9 +282,9 @@ check_validity_mo_source <- function(x, refer_to_name = "`reference_df`", stop_o
return(FALSE)
}
}
if (!all(x$mo %in% c("", microorganisms$mo), na.rm = TRUE)) {
if (!all(x$mo %in% c("", microorganisms$mo, microorganisms$fullname), na.rm = TRUE)) {
if (stop_on_error == TRUE) {
invalid <- x[which(!x$mo %in% c("", microorganisms$mo)), , drop = FALSE]
invalid <- x[which(!x$mo %in% c("", microorganisms$mo, microorganisms$fullname)), , drop = FALSE]
if (nrow(invalid) > 1) {
plural <- "s"
} else {

Binary file not shown.

View File

@ -43,7 +43,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="https://msberends.github.io/AMR/index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>

View File

@ -17,7 +17,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>

View File

@ -44,7 +44,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>

View File

@ -17,7 +17,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>

View File

@ -47,7 +47,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>

View File

@ -17,7 +17,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>
@ -157,17 +157,18 @@
</div>
<div class="section level2">
<h2 class="page-header" data-toc-text="1.8.1.9002" id="amr-1819002">
<code>AMR</code> 1.8.1.9002<a class="anchor" aria-label="anchor" href="#amr-1819002"></a></h2>
<h2 class="page-header" data-toc-text="1.8.1.9003" id="amr-1819003">
<code>AMR</code> 1.8.1.9003<a class="anchor" aria-label="anchor" href="#amr-1819003"></a></h2>
<div class="section level3">
<h3 id="last-updated-may-1-8-1-9002"><small>Last updated: 9 May 2022</small><a class="anchor" aria-label="anchor" href="#last-updated-may-1-8-1-9002"></a></h3>
<h3 id="last-updated-may-1-8-1-9003"><small>Last updated: 9 May 2022</small><a class="anchor" aria-label="anchor" href="#last-updated-may-1-8-1-9003"></a></h3>
<div class="section level4">
<h4 id="changed-1-8-1-9002">Changed<a class="anchor" aria-label="anchor" href="#changed-1-8-1-9002"></a></h4>
<ul><li>Removed <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> for MIC values, since MIC are not integer values and running <code><a href="https://rdrr.io/r/base/table.html" class="external-link">table()</a></code> on MIC values will consequently fail for not being able to retrieve the level position (as thats how normally <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> on <code>factor</code>s work)</li>
<h4 id="changed-1-8-1-9003">Changed<a class="anchor" aria-label="anchor" href="#changed-1-8-1-9003"></a></h4>
<ul><li>Removed <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> for MIC values, since MIC are not integer values and running <code><a href="https://rdrr.io/r/base/table.html" class="external-link">table()</a></code> on MIC values consequently failed for not being able to retrieve the level position (as thats how normally <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> on <code>factor</code>s work)</li>
<li>
<code><a href="https://rdrr.io/r/base/droplevels.html" class="external-link">droplevels()</a></code> on MIC will now return a common <code>factor</code> at default and will lose the <code>&lt;mic&gt;</code> class. Use <code>droplevels(..., as.mic = TRUE)</code> to keep the <code>&lt;mic&gt;</code> class.</li>
<li>Small fix for using <code><a href="../reference/ab_from_text.html">ab_from_text()</a></code>
</li>
<li>Fixes for reading in text files using <code><a href="../reference/mo_source.html">set_mo_source()</a></code>, which now also allows the source file to contain valid taxonomic names instead of only valid microorganism ID of this package</li>
</ul></div>
</div>
</div>

View File

@ -17,7 +17,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>

View File

@ -18,7 +18,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>
@ -31,7 +31,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p
</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span>
How to
@ -175,15 +175,15 @@ This is the fastest way to have your organisation (or analysis) specific codes p
<div id="arguments">
<h2>Arguments</h2>
<dl><dt>path</dt>
<dd><p>location of your reference file, see <em>Details</em>. Can be <code>""</code>, <code>NULL</code> or <code>FALSE</code> to delete the reference file.</p></dd>
<dd><p>location of your reference file, this can be any text file (comma-, tab- or pipe-separated) or an Excel file (see <em>Details</em>). Can also be <code>""</code>, <code>NULL</code> or <code>FALSE</code> to delete the reference file.</p></dd>
<dt>destination</dt>
<dd><p>destination of the compressed data file, default to the user's home directory.</p></dd>
</dl></div>
<div id="details">
<h2>Details</h2>
<p>The reference file can be a text file separated with commas (CSV) or tabs or pipes, an Excel file (either 'xls' or 'xlsx' format) or an <span style="R">R</span> object file (extension '.rds'). To use an Excel file, you will need to have the <code>readxl</code> package installed.</p>
<p><code>set_mo_source()</code> will check the file for validity: it must be a <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a>, must have a column named <code>"mo"</code> which contains values from <code><a href="microorganisms.html">microorganisms$mo</a></code> and must have a reference column with your own defined values. If all tests pass, <code>set_mo_source()</code> will read the file into <span style="R">R</span> and will ask to export it to <code>"~/mo_source.rds"</code>. The CRAN policy disallows packages to write to the file system, although '<em>exceptions may be allowed in interactive sessions if the package obtains confirmation from the user</em>'. For this reason, this function only works in interactive sessions so that the user can <strong>specifically confirm and allow</strong> that this file will be created. The destination of this file can be set with the <code>destination</code> argument and defaults to the user's home directory. It can also be set as an <span style="R">R</span> option, using <code>options(AMR_mo_source = "my/location/file.rds")</code>.</p>
<p>The created compressed data file <code>"mo_source.rds"</code> will be used at default for MO determination (function <code><a href="as.mo.html">as.mo()</a></code> and consequently all <code>mo_*</code> functions like <code><a href="mo_property.html">mo_genus()</a></code> and <code><a href="mo_property.html">mo_gramstain()</a></code>). The location and timestamp of the original file will be saved as an attribute to the compressed data file.</p>
<p><code>set_mo_source()</code> will check the file for validity: it must be a <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a>, must have a column named <code>"mo"</code> which contains values from <code><a href="microorganisms.html">microorganisms$mo</a></code> or <code><a href="microorganisms.html">microorganisms$fullname</a></code> and must have a reference column with your own defined values. If all tests pass, <code>set_mo_source()</code> will read the file into <span style="R">R</span> and will ask to export it to <code>"~/mo_source.rds"</code>. The CRAN policy disallows packages to write to the file system, although '<em>exceptions may be allowed in interactive sessions if the package obtains confirmation from the user</em>'. For this reason, this function only works in interactive sessions so that the user can <strong>specifically confirm and allow</strong> that this file will be created. The destination of this file can be set with the <code>destination</code> argument and defaults to the user's home directory. It can also be set as an <span style="R">R</span> option, using <code>options(AMR_mo_source = "my/location/file.rds")</code>.</p>
<p>The created compressed data file <code>"mo_source.rds"</code> will be used at default for MO determination (function <code><a href="as.mo.html">as.mo()</a></code> and consequently all <code>mo_*</code> functions like <code><a href="mo_property.html">mo_genus()</a></code> and <code><a href="mo_property.html">mo_gramstain()</a></code>). The location and timestamp of the original file will be saved as an <a href="https://rdrr.io/r/base/attributes.html" class="external-link">attribute</a> to the compressed data file.</p>
<p>The function <code>get_mo_source()</code> will return the data set by reading <code>"mo_source.rds"</code> with <code><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">readRDS()</a></code>. If the original file has changed (by checking the location and timestamp of the original file), it will call <code>set_mo_source()</code> to update the data file automatically if used in an interactive session.</p>
<p>Reading an Excel file (<code>.xlsx</code>) with only one row has a size of 8-9 kB. The compressed file created with <code>set_mo_source()</code> will then have a size of 0.1 kB and can be read by <code>get_mo_source()</code> in only a couple of microseconds (millionths of a second).</p>
</div>
@ -192,11 +192,11 @@ This is the fastest way to have your organisation (or analysis) specific codes p
<p>Imagine this data on a sheet of an Excel file (mo codes were looked up in the <a href="microorganisms.html">microorganisms</a> data set). The first column contains the organisation specific codes, the second column contains an MO code from this package:</p><div class="sourceCode"><pre><code> | A | B |
--|--------------------|--------------|
<p>Imagine this data on a sheet of an Excel file. The first column contains the organisation specific codes, the second column contains valid taxonomic names:</p><div class="sourceCode"><pre><code> | A | B |
--|--------------------|-----------------------|
1 | Organisation XYZ | mo |
2 | lab_mo_ecoli | B_ESCHR_COLI |
3 | lab_mo_kpneumoniae | B_KLBSL_PNMN |
2 | lab_mo_ecoli | Escherichia coli |
3 | lab_mo_kpneumoniae | Klebsiella pneumoniae |
4 | | |
</code></pre></div>
@ -221,11 +221,11 @@ This is the fastest way to have your organisation (or analysis) specific codes p
<span class="co">#&gt; [1] B_ESCHR_COLI B_ESCHR_COLI B_ESCHR_COLI</span></code></pre></div>
<p>If we edit the Excel file by, let's say, adding row 4 like this:</p><div class="sourceCode"><pre><code> | A | B |
--|--------------------|--------------|
--|--------------------|-----------------------|
1 | Organisation XYZ | mo |
2 | lab_mo_ecoli | B_ESCHR_COLI |
3 | lab_mo_kpneumoniae | B_KLBSL_PNMN |
4 | lab_Staph_aureus | B_STPHY_AURS |
2 | lab_mo_ecoli | Escherichia coli |
3 | lab_mo_kpneumoniae | Klebsiella pneumoniae |
4 | lab_Staph_aureus | Staphylococcus aureus |
5 | | |
</code></pre></div>
@ -271,7 +271,7 @@ The <a href="lifecycle.html">lifecycle</a> of this function is <strong>stable</s
</div>
<div class="pkgdown">
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.2.</p>
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
</div>
</footer></div>

View File

@ -17,7 +17,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9002</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9003</span>
</span>
</div>

View File

@ -42,7 +42,8 @@ expect_inherits(x[1], "mic")
expect_inherits(x[[1]], "mic")
expect_inherits(c(x[1], x[9]), "mic")
expect_inherits(unique(x[1], x[9]), "mic")
expect_inherits(droplevels(c(x[1], x[9])), "mic")
expect_inherits(droplevels(c(x[1], x[9]), as.mic = TRUE), "factor")
expect_inherits(droplevels(c(x[1], x[9]), as.mic = TRUE), "mic")
x[2] <- 32
expect_inherits(x, "mic")
expect_warning(as.mic("INVALID VALUE"))

View File

@ -14,7 +14,7 @@ set_mo_source(
get_mo_source(destination = getOption("AMR_mo_source", "~/mo_source.rds"))
}
\arguments{
\item{path}{location of your reference file, see \emph{Details}. Can be \code{""}, \code{NULL} or \code{FALSE} to delete the reference file.}
\item{path}{location of your reference file, this can be any text file (comma-, tab- or pipe-separated) or an Excel file (see \emph{Details}). Can also be \code{""}, \code{NULL} or \code{FALSE} to delete the reference file.}
\item{destination}{destination of the compressed data file, default to the user's home directory.}
}
@ -26,9 +26,9 @@ This is \strong{the fastest way} to have your organisation (or analysis) specifi
\details{
The reference file can be a text file separated with commas (CSV) or tabs or pipes, an Excel file (either 'xls' or 'xlsx' format) or an \R object file (extension '.rds'). To use an Excel file, you will need to have the \code{readxl} package installed.
\code{\link[=set_mo_source]{set_mo_source()}} will check the file for validity: it must be a \link{data.frame}, must have a column named \code{"mo"} which contains values from \code{\link[=microorganisms]{microorganisms$mo}} and must have a reference column with your own defined values. If all tests pass, \code{\link[=set_mo_source]{set_mo_source()}} will read the file into \R and will ask to export it to \code{"~/mo_source.rds"}. The CRAN policy disallows packages to write to the file system, although '\emph{exceptions may be allowed in interactive sessions if the package obtains confirmation from the user}'. For this reason, this function only works in interactive sessions so that the user can \strong{specifically confirm and allow} that this file will be created. The destination of this file can be set with the \code{destination} argument and defaults to the user's home directory. It can also be set as an \R option, using \code{options(AMR_mo_source = "my/location/file.rds")}.
\code{\link[=set_mo_source]{set_mo_source()}} will check the file for validity: it must be a \link{data.frame}, must have a column named \code{"mo"} which contains values from \code{\link[=microorganisms]{microorganisms$mo}} or \code{\link[=microorganisms]{microorganisms$fullname}} and must have a reference column with your own defined values. If all tests pass, \code{\link[=set_mo_source]{set_mo_source()}} will read the file into \R and will ask to export it to \code{"~/mo_source.rds"}. The CRAN policy disallows packages to write to the file system, although '\emph{exceptions may be allowed in interactive sessions if the package obtains confirmation from the user}'. For this reason, this function only works in interactive sessions so that the user can \strong{specifically confirm and allow} that this file will be created. The destination of this file can be set with the \code{destination} argument and defaults to the user's home directory. It can also be set as an \R option, using \code{options(AMR_mo_source = "my/location/file.rds")}.
The created compressed data file \code{"mo_source.rds"} will be used at default for MO determination (function \code{\link[=as.mo]{as.mo()}} and consequently all \verb{mo_*} functions like \code{\link[=mo_genus]{mo_genus()}} and \code{\link[=mo_gramstain]{mo_gramstain()}}). The location and timestamp of the original file will be saved as an attribute to the compressed data file.
The created compressed data file \code{"mo_source.rds"} will be used at default for MO determination (function \code{\link[=as.mo]{as.mo()}} and consequently all \verb{mo_*} functions like \code{\link[=mo_genus]{mo_genus()}} and \code{\link[=mo_gramstain]{mo_gramstain()}}). The location and timestamp of the original file will be saved as an \link[base:attributes]{attribute} to the compressed data file.
The function \code{\link[=get_mo_source]{get_mo_source()}} will return the data set by reading \code{"mo_source.rds"} with \code{\link[=readRDS]{readRDS()}}. If the original file has changed (by checking the location and timestamp of the original file), it will call \code{\link[=set_mo_source]{set_mo_source()}} to update the data file automatically if used in an interactive session.
@ -37,11 +37,11 @@ Reading an Excel file (\code{.xlsx}) with only one row has a size of 8-9 kB. The
\section{How to Setup}{
Imagine this data on a sheet of an Excel file (mo codes were looked up in the \link{microorganisms} data set). The first column contains the organisation specific codes, the second column contains an MO code from this package:\preformatted{ | A | B |
--|--------------------|--------------|
Imagine this data on a sheet of an Excel file. The first column contains the organisation specific codes, the second column contains valid taxonomic names:\preformatted{ | A | B |
--|--------------------|-----------------------|
1 | Organisation XYZ | mo |
2 | lab_mo_ecoli | B_ESCHR_COLI |
3 | lab_mo_kpneumoniae | B_KLBSL_PNMN |
2 | lab_mo_ecoli | Escherichia coli |
3 | lab_mo_kpneumoniae | Klebsiella pneumoniae |
4 | | |
}
@ -69,11 +69,11 @@ as.mo(c("Escherichia coli", "E. coli", "lab_mo_ecoli"))
}
If we edit the Excel file by, let's say, adding row 4 like this:\preformatted{ | A | B |
--|--------------------|--------------|
--|--------------------|-----------------------|
1 | Organisation XYZ | mo |
2 | lab_mo_ecoli | B_ESCHR_COLI |
3 | lab_mo_kpneumoniae | B_KLBSL_PNMN |
4 | lab_Staph_aureus | B_STPHY_AURS |
2 | lab_mo_ecoli | Escherichia coli |
3 | lab_mo_kpneumoniae | Klebsiella pneumoniae |
4 | lab_Staph_aureus | Staphylococcus aureus |
5 | | |
}