1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-11 10:21:54 +02:00

support new mo codes

This commit is contained in:
2022-12-27 15:16:15 +01:00
parent e493248ea5
commit f619fb683b
127 changed files with 859 additions and 443 deletions

View File

@ -16,20 +16,37 @@ clear_custom_antimicrobials()
With \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} you can add your own custom antimicrobial drug codes to the \code{AMR} package.
}
\details{
Due to how \R works, the \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} function has to be run in every \R session - added antimicrobials are not stored between sessions and are thus lost when \R is exited. It is possible to save the antimicrobial additions to your \code{.Rprofile} file to circumvent this, although this requires to load the \code{AMR} package at every start-up:
\strong{Important:} Due to how \R works, the \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} function has to be run in every \R session - added antimicrobials are not stored between sessions and are thus lost when \R is exited.
\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Open .Rprofile file
utils::file.edit("~/.Rprofile")
There are two ways to automate this process:
# Add custom antibiotic drug codes:
library(AMR)
add_custom_antimicrobials(
data.frame(ab = "TESTAB",
name = "Test Antibiotic",
group = "Test Group")
)
\strong{Method 1:} Save the antimicrobials to a local or remote file (can even be the internet). To use this method:
\enumerate{
\item Create a data set in the structure of the \link{antibiotics} data set (containing at the very least columns "ab" and "name") and save it with \code{\link[=saveRDS]{saveRDS()}} to a location of choice, e.g. \code{"~/my_custom_ab.rds"}, or any remote location.
\item Set the file location to the \code{AMR_custom_ab} \R option: \code{options(AMR_custom_ab = "~/my_custom_ab.rds")}. This can even be a remote file location, such as an https URL. Since options are not saved between \R sessions, it is best to save this option to the \code{.Rprofile} file so that it will loaded on start-up of \R. To do this, open the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}, add this text and save the file:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Add custom antibiotic drug codes:
options(AMR_custom_ab = "~/my_custom_ab.rds")
}\if{html}{\out{</div>}}
Upon package load, this file will be loaded and run through the \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} function.
}
\strong{Method 2:} Save the antimicrobial additions directly to your \code{.Rprofile} file. An important downside is that this requires to load the \code{AMR} package at every start-up. To use this method:
\enumerate{
\item Edit the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}.
\item Add a text like below and save the file:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{ # Add custom antibiotic drug codes:
library(AMR)
add_custom_antimicrobials(
data.frame(ab = "TESTAB",
name = "Test Antibiotic",
group = "Test Group")
)
}\if{html}{\out{</div>}}
}
Use \code{\link[=clear_custom_antimicrobials]{clear_custom_antimicrobials()}} to clear the previously added antimicrobials.
}
\examples{
@ -67,7 +84,7 @@ add_custom_antimicrobials(
ab = "COFLU",
name = "Co-fluampicil",
atc = "J01CR50",
group = "Beta-lactams/penicillines"
group = "Beta-lactams/penicillins"
)
)
ab_atc("Co-fluampicil")
@ -83,3 +100,6 @@ x
x[, betalactams()]
}
}
\seealso{
\code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} to add custom microorganisms to this package.
}

View File

@ -0,0 +1,86 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_custom_microorganisms.R
\name{add_custom_microorganisms}
\alias{add_custom_microorganisms}
\alias{clear_custom_microorganisms}
\title{Add Custom Microorganisms to This Package}
\usage{
add_custom_microorganisms(x)
clear_custom_microorganisms()
}
\arguments{
\item{x}{a \link{data.frame} resembling the \link{microorganisms} data set, at least containing columns "mo", "genus" and "species"}
}
\description{
With \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} you can add your own custom antimicrobial drug codes to the \code{AMR} package.
}
\details{
This function will fill in missing taxonomy for you, if specific taxonomic columns are missing, see \emph{Examples}.
\strong{Important:} Due to how \R works, the \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} function has to be run in every \R session - added microorganisms are not stored between sessions and are thus lost when \R is exited.
There are two ways to automate this process:
\strong{Method 1:} Save the microorganisms to a local or remote file (can even be the internet). To use this method:
\enumerate{
\item Create a data set in the structure of the \link{microorganisms} data set (containing at the very least columns "ab" and "name") and save it with \code{\link[=saveRDS]{saveRDS()}} to a location of choice, e.g. \code{"~/my_custom_mo.rds"}, or any remote location.
\item Set the file location to the \code{AMR_custom_mo} \R option: \code{options(AMR_custom_mo = "~/my_custom_mo.rds")}. This can even be a remote file location, such as an https URL. Since options are not saved between \R sessions, it is best to save this option to the \code{.Rprofile} file so that it will loaded on start-up of \R. To do this, open the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}, add this text and save the file:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Add custom microorganism codes:
options(AMR_custom_mo = "~/my_custom_mo.rds")
}\if{html}{\out{</div>}}
Upon package load, this file will be loaded and run through the \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} function.
}
\strong{Method 2:} Save the microorganism directly to your \code{.Rprofile} file. An important downside is that this requires to load the \code{AMR} package at every start-up. To use this method:
\enumerate{
\item Edit the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}.
\item Add a text like below and save the file:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{ # Add custom antibiotic drug codes:
library(AMR)
add_custom_microorganisms(
data.frame(mo = "ENT_ASB_CLO",
genus = "Enterobacter",
species = "asburiae/cloacae")
)
}\if{html}{\out{</div>}}
}
Use \code{\link[=clear_custom_microorganisms]{clear_custom_microorganisms()}} to clear the previously added antimicrobials.
}
\examples{
\donttest{
# a combination of species is not formal taxonomy, so
# this will result in only "Enterobacter asburiae":
mo_name("Enterobacter asburiae/cloacae")
# now add a custom entry - it will be considered by as.mo() and
# all mo_*() functions
add_custom_microorganisms(
data.frame(mo = "ENT_ASB_CLO",
genus = "Enterobacter",
species = "asburiae/cloacae"
)
)
# "ENT_ASB_CLO" is now a new microorganism:
mo_name("Enterobacter asburiae/cloacae")
as.mo("ent_asb_clo")
mo_name("ent_asb_clo")
# all internal algorithms will work as well:
mo_name("Ent asburia cloacae")
# and even the taxonomy was added based on the genus!
mo_family("ent_asb_clo")
mo_gramstain("Enterobacter asburiae/cloacae")
mo_info("ent_asb_clo")
}
}
\seealso{
\code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} to add custom antimicrobials to this package.
}