[Stable] A function to call an epidm lookup table and recode where we are aware of a new value.

Built in are the organism re-classifications and specimen_type groupings and a manual mode.

lookup_recode(src, type = c("species", "specimen", "manual"), .import = NULL)

Arguments

src

a character, vector or column containing the value(s) to be referenced

type

a character value to denote the lookup table used

.import

a list in the order list(new,old) containing the values for another lookup table existing in the environment

Value

a list object of the recoded field

Examples

df <- data.frame(
  spec = c(
    sample(grep(")",
                respeciate_organism$previous_organism_name,
                value=TRUE,
                invert = TRUE),
           9),
    "ESCHERICHIA COLI","SARS-COV-2","CANDIDA AUREUS"),
  type = sample(specimen_type_grouping$specimen_type,12),
  date = sample(seq.Date(from = Sys.Date()-365,
                         to = Sys.Date(),
                         by = "day"),12)
)
df <- df[order(df$date),]

# show the data before the changes
df
#>                            spec                   type       date
#> 5  TETRATHIOBACTER KASHMIRENSIS               PERNASAL 2021-08-03
#> 8         STREPTOCOCCUS GROUP D                    EYE 2021-09-19
#> 3         BACTEROIDES CORRODENS                 CORNEA 2021-10-02
#> 11                   SARS-COV-2                 BREAST 2021-11-30
#> 7        ACTINOBACULUM SCHAALII                 TISSUE 2022-03-21
#> 1       RHODOCOCCUS BRONCHIALIS      WOUND (TRAUMATIC) 2022-04-09
#> 9      MORAXELLA PHENYLPYRUVICA           HICKMAN LINE 2022-05-02
#> 10             ESCHERICHIA COLI PRODUCTS OF CONCEPTION 2022-05-10
#> 6       PROPIONIBACTERIUM ACNES          SKIN SCRAPING 2022-05-12
#> 4       EUBACTERIUM AEROFACIENS                   BONE 2022-06-10
#> 12               CANDIDA AUREUS                 SPUTUM 2022-07-02
#> 2    STREPTOCOCCUS GROUP D STEM            PERICARDIUM 2022-07-03

# check the lookup tables
# observe the changes
head(respeciate_organism[1:2])
#>                  previous_organism_name       organism_species_name
#> 1             ALCALIGENES DENITRIFICANS ACHROMOBACTER DENITRIFICANS
#> 2                ALCALIGENES PIECHAUDII    ACHROMOBACTER PIECHAUDII
#> 3              ALCALIGENES XYLOSOXIDANS  ACHROMOBACTER XYLOSOXIDANS
#> 4 ALCALIGENES XYLOSOXIDANS XYLOSOXIDANS  ACHROMOBACTER XYLOSOXIDANS
#> 5                ACTINOBACULUM SCHAALII       ACTINOTIGNUM SCHAALII
#> 6          TETRATHIOBACTER KASHMIRENSIS      ADVENELLA KASHMIRENSIS
df$species <- lookup_recode(df$spec,'species')
df[,c('spec','species','date')]
#>                            spec                       species       date
#> 5  TETRATHIOBACTER KASHMIRENSIS        ADVENELLA KASHMIRENSIS 2021-08-03
#> 8         STREPTOCOCCUS GROUP D         ENTEROCOCCUS FAECALIS 2021-09-19
#> 3         BACTEROIDES CORRODENS     CAMPYLOBACTER UREOLYTICUS 2021-10-02
#> 11                   SARS-COV-2                    SARS-COV-2 2021-11-30
#> 7        ACTINOBACULUM SCHAALII         ACTINOTIGNUM SCHAALII 2022-03-21
#> 1       RHODOCOCCUS BRONCHIALIS          GORDONIA BRONCHIALIS 2022-04-09
#> 9      MORAXELLA PHENYLPYRUVICA PSYCHROBACTER PHENYLPYRUVICUS 2022-05-02
#> 10             ESCHERICHIA COLI              ESCHERICHIA COLI 2022-05-10
#> 6       PROPIONIBACTERIUM ACNES           CUTIBACTERIUM ACNES 2022-05-12
#> 4       EUBACTERIUM AEROFACIENS       COLLINSELLA AEROFACIENS 2022-06-10
#> 12               CANDIDA AUREUS                CANDIDA AUREUS 2022-07-02
#> 2    STREPTOCOCCUS GROUP D STEM         ENTEROCOCCUS FAECALIS 2022-07-03

head(specimen_type_grouping)
#>      specimen_type specimen_group
#> 1            BLOOD          Blood
#> 2       CORD BLOOD          Blood
#> 3            JOINT Bones & Joints
#> 4   SYNOVIAL FLUID Bones & Joints
#> 5             BONE Bones & Joints
#> 6 JOINT PROSTHESIS Bones & Joints
df$grp <- lookup_recode(df$type,'specimen')
df[,c('species','type','grp','date')]
#>                          species                   type            grp
#> 5         ADVENELLA KASHMIRENSIS               PERNASAL  URT/Mouth/Ear
#> 8          ENTEROCOCCUS FAECALIS                    EYE  Swabs-General
#> 3      CAMPYLOBACTER UREOLYTICUS                 CORNEA        Tissues
#> 11                    SARS-COV-2                 BREAST        Tissues
#> 7          ACTINOTIGNUM SCHAALII                 TISSUE        Tissues
#> 1           GORDONIA BRONCHIALIS      WOUND (TRAUMATIC)    Wound Swabs
#> 9  PSYCHROBACTER PHENYLPYRUVICUS           HICKMAN LINE   Tips & Lines
#> 10              ESCHERICHIA COLI PRODUCTS OF CONCEPTION        Tissues
#> 6            CUTIBACTERIUM ACNES          SKIN SCRAPING        Tissues
#> 4        COLLINSELLA AEROFACIENS                   BONE Bones & Joints
#> 12                CANDIDA AUREUS                 SPUTUM         Fluids
#> 2          ENTEROCOCCUS FAECALIS            PERICARDIUM        Tissues
#>          date
#> 5  2021-08-03
#> 8  2021-09-19
#> 3  2021-10-02
#> 11 2021-11-30
#> 7  2022-03-21
#> 1  2022-04-09
#> 9  2022-05-02
#> 10 2022-05-10
#> 6  2022-05-12
#> 4  2022-06-10
#> 12 2022-07-02
#> 2  2022-07-03

# for a tidyverse use
# df %>% mutate(spec=lookup_recode(spec,'species))

# manual input of your own lookup
# .import=list(new,old)
lookup_recode(
  "ALCALIGENES DENITRIFICANS",
  type = 'manual',
  .import=list(respeciate_organism$organism_species_name,
               respeciate_organism$previous_organism_name)
  )
#> [[1]]
#> [1] "ACHROMOBACTER DENITRIFICANS"
#>