Add Custom Antimicrobials to This Package
Source:R/add_custom_antimicrobials.R
add_custom_antimicrobials.Rd
With add_custom_antimicrobials()
you can add your own custom antimicrobial codes to the AMR
package.
Arguments
- x
a data.frame resembling the antibiotics data set, at least containing columns "ab" and "name"
Details
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. It is possible to save the antimicrobial additions to your .Rprofile
file to circumvent this, although this requires to load the AMR
package at every start-up:
# Open .Rprofile file
utils::file.edit("~/.Rprofile")
# Add custom antibiotic codes:
library(AMR)
add_custom_antimicrobials(
data.frame(ab = "TEST",
name = "Test Antibiotic",
group = "Test Group")
)
Use clear_custom_antimicrobials()
to clear the previously added antimicrobials.
Examples
# returns NA and throws a warning (which is now suppressed):
suppressWarnings(
as.ab("test")
)
#> Class <ab>
#> [1] <NA>
# now add a custom entry - it will be considered by as.ab() and
# all ab_*() functions
add_custom_antimicrobials(
data.frame(ab = "TEST",
name = "Test Antibiotic",
# you can add any property present in the
# 'antibiotics' data set, such as 'group':
group = "Test Group")
)
#> ℹ Added one record to internal `antibiotics` data set.
# "test" is now a new antibiotic:
as.ab("test")
#> Class <ab>
#> [1] TEST
ab_name("test")
#> [1] "Test Antibiotic"
ab_group("test")
#> [1] "Test Group"
ab_info("test")
#> $ab
#> [1] "TEST"
#>
#> $cid
#> [1] NA
#>
#> $name
#> [1] "Test Antibiotic"
#>
#> $group
#> [1] "Test Group"
#>
#> $atc
#> NULL
#>
#> $atc_group1
#> [1] NA
#>
#> $atc_group2
#> [1] NA
#>
#> $tradenames
#> NULL
#>
#> $loinc
#> NULL
#>
#> $ddd
#> $ddd$oral
#> $ddd$oral$amount
#> [1] NA
#>
#> $ddd$oral$units
#> [1] NA
#>
#>
#> $ddd$iv
#> $ddd$iv$amount
#> [1] NA
#>
#> $ddd$iv$units
#> [1] NA
#>
#>
#>