Details
Important: Due to how R works, the 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 circumvent this and automate the process of adding antimicrobials:
-
Method 1: Using the package option AMR_custom_ab, which is the preferred method. To use this method:
Create a data set in the structure of the antimicrobials data set (containing at the very least columns "ab" and "name") and save it with saveRDS() to a location of choice, e.g. "~/my_custom_ab.rds", or any remote location.
+Method 1: Using the package option AMR_custom_ab, which is the preferred method. To use this method:
Create a data set in the structure of the antimicrobials data set (containing at the very least columns "ab" and "name", or only columns "ab" and "synonyms" for synonyms of existing antimicrobials) and save it with saveRDS() to a location of choice, e.g. "~/my_custom_ab.rds", or any remote location.
Set the file location to the package option AMR_custom_ab: 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 .Rprofile file so that it will be loaded on start-up of R. To do this, open the .Rprofile file using e.g. utils::file.edit("~/.Rprofile"), add this text and save the file:
# Add custom antimicrobial codes:
options(AMR_custom_ab = "~/my_custom_ab.rds")
-Upon package load, this file will be loaded and run through the add_custom_antimicrobials() function.
+Upon package load, this file will be loaded and run through the add_custom_antimicrobials() function.
+This file can also hold synonyms for antimicrobials that already exist, such as local trade names: rows with an existing code in column "ab" and only column "synonyms" filled (one synonym per row, codes may repeat) are passed on to add_custom_antimicrobial_synonyms(). Rows with an existing code that have any other column filled still give an error. Synonyms must be valid UTF-8 text; convert other encodings first, e.g. with iconv(x, from = "CP949", to = "UTF-8").
Method 2: Loading the antimicrobial additions directly from your .Rprofile file. Note that the definitions will be stored in a user-specific R file, which is a suboptimal workflow. To use this method:
Edit the .Rprofile file using e.g. utils::file.edit("~/.Rprofile").
Add a text like below and save the file:
# Add custom antibiotic drug codes:
@@ -85,7 +96,8 @@
name = "Test Antibiotic",
group = "Test Group")
)
-
Use clear_custom_antimicrobials() to clear the previously added antimicrobials.
+
Use add_custom_antimicrobial_synonyms() to add extra names, such as local trade names, to antimicrobials that already exist (including antimicrobials added with add_custom_antimicrobials()). These synonyms are recognised by as.ab() and all ab_*() functions. Synonyms may contain non-ASCII characters (e.g. trade names in other scripts): they are matched against the input as given, before as.ab() transliterates the input to ASCII. Matching ignores case, all white space (including no-break and ideographic spaces) and zero-width characters. If the input does not match as given, a trailing part in parentheses or brackets (such as (piperacillin, tazobactam)) and a trailing strength written as a number with a unit symbol (such as 4.5g, 4/0.5 g or 500 mg/mL) are removed one at a time, and matching is tried again after each removal, so that the longest registered synonym wins. Full-width characters are read as their ASCII equivalents. No words are removed, in any language: to recognise a name with a dosage form (such as Inj), add that variant as a synonym as well. Only user-added synonyms are matched this way, there is no other fuzzy matching for them, and a strength on its own is never matched to a user-added synonym. A synonym cannot be added if it already identifies another antimicrobial as its code, name, synonym, abbreviation, ATC code, CID or LOINC code, also when written with other punctuation (such as J01-CR05).
+
Use clear_custom_antimicrobials() to clear the previously added antimicrobials and synonyms.