mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 18:46:11 +01:00
106 lines
3.9 KiB
R
106 lines
3.9 KiB
R
% Generated by roxygen2: do not edit by hand
|
|
% Please edit documentation in R/add_custom_antimicrobials.R
|
|
\name{add_custom_antimicrobials}
|
|
\alias{add_custom_antimicrobials}
|
|
\alias{clear_custom_antimicrobials}
|
|
\title{Add Custom Antimicrobials to This Package}
|
|
\usage{
|
|
add_custom_antimicrobials(x)
|
|
|
|
clear_custom_antimicrobials()
|
|
}
|
|
\arguments{
|
|
\item{x}{a \link{data.frame} resembling the \link{antibiotics} data set, at least containing columns "ab" and "name"}
|
|
}
|
|
\description{
|
|
With \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} you can add your own custom antimicrobial drug codes to the \code{AMR} package.
|
|
}
|
|
\details{
|
|
\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.
|
|
|
|
There are two ways to automate this process:
|
|
|
|
\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{
|
|
\donttest{
|
|
|
|
# returns NA and throws a warning (which is now suppressed):
|
|
suppressWarnings(
|
|
as.ab("testab")
|
|
)
|
|
|
|
# now add a custom entry - it will be considered by as.ab() and
|
|
# all ab_*() functions
|
|
add_custom_antimicrobials(
|
|
data.frame(
|
|
ab = "TESTAB",
|
|
name = "Test Antibiotic",
|
|
# you can add any property present in the
|
|
# 'antibiotics' data set, such as 'group':
|
|
group = "Test Group"
|
|
)
|
|
)
|
|
|
|
# "testab" is now a new antibiotic:
|
|
as.ab("testab")
|
|
ab_name("testab")
|
|
ab_group("testab")
|
|
|
|
ab_info("testab")
|
|
|
|
|
|
# Add Co-fluampicil, which is one of the many J01CR50 codes, see
|
|
# https://www.whocc.no/ddd/list_of_ddds_combined_products/
|
|
add_custom_antimicrobials(
|
|
data.frame(
|
|
ab = "COFLU",
|
|
name = "Co-fluampicil",
|
|
atc = "J01CR50",
|
|
group = "Beta-lactams/penicillins"
|
|
)
|
|
)
|
|
ab_atc("Co-fluampicil")
|
|
ab_name("J01CR50")
|
|
|
|
# even antibiotic selectors work
|
|
x <- data.frame(
|
|
random_column = "some value",
|
|
coflu = as.rsi("S"),
|
|
ampicillin = as.rsi("R")
|
|
)
|
|
x
|
|
x[, betalactams()]
|
|
}
|
|
}
|
|
\seealso{
|
|
\code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} to add custom microorganisms to this package.
|
|
}
|