Some samples within SGSS are submitted by laboratories as "GENUS SP" or "GENUS UNNAMED". However, they may also have a fully identified sample taken from the same site within a recent time period. This function captures species_col from another sample within X-days of an unspeciated isolate.
Usage
respeciate_generic(
x,
group_vars,
species_col,
date_col,
window = c(0:Inf),
.forceCopy = FALSE
)
Arguments
- x
a data.frame or data.table object
- group_vars
the minimum grouping set of variables for like samples in a character vector; suggest c('patient_id','specimen_type','genus')
- species_col
a character containing the column with the organism species_col name
- date_col
a character containing the column with the specimen/sample date_col
- window
an integer representing the number of days for which you will allow a sample to be respeciated
- .forceCopy
default FALSE; TRUE will force data.table to take a copy instead of editing the data without reference
Examples
df <- data.frame(
ptid = c(round(runif(25,1,5))),
spec = sample(c("KLEBSIELLA SP",
"KLEBSIELLA UNNAMED",
"KLEBSIELLA PNEUMONIAE",
"KLEBEIELLA OXYTOCA"),
25,replace = TRUE),
type = "BLOOD",
specdate = sample(seq.Date(Sys.Date()-21,Sys.Date(),"day"),25,replace = TRUE)
)
respeciate_generic(x=df,
group_vars=c('ptid','type'),
species_col='spec',
date_col='specdate',
window = 14)[]
#> 14-day round 1: 7 SP or UNNAMMED isolates respeciated
#> 14-day round 2: 1 SP or UNNAMMED isolates respeciated
#> 14-day round 3: 0 SP or UNNAMMED isolates respeciated
#> ptid spec type specdate
#> <num> <char> <char> <Date>
#> 1: 1 KLEBSIELLA SP BLOOD 2024-08-16
#> 2: 2 KLEBEIELLA OXYTOCA BLOOD 2024-07-29
#> 3: 2 KLEBEIELLA OXYTOCA BLOOD 2024-07-29
#> 4: 2 KLEBEIELLA OXYTOCA BLOOD 2024-08-02
#> 5: 2 KLEBEIELLA OXYTOCA BLOOD 2024-08-02
#> 6: 2 KLEBEIELLA OXYTOCA BLOOD 2024-08-02
#> 7: 2 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-03
#> 8: 2 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-04
#> 9: 2 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-09
#> 10: 2 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-10
#> 11: 3 KLEBSIELLA PNEUMONIAE BLOOD 2024-07-30
#> 12: 3 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-03
#> 13: 3 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-07
#> 14: 3 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-08
#> 15: 3 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-09
#> 16: 3 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-10
#> 17: 3 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-14
#> 18: 3 KLEBEIELLA OXYTOCA BLOOD 2024-08-15
#> 19: 3 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-19
#> 20: 4 KLEBSIELLA SP BLOOD 2024-08-04
#> 21: 4 KLEBSIELLA SP BLOOD 2024-08-11
#> 22: 4 KLEBSIELLA SP BLOOD 2024-08-14
#> 23: 5 KLEBEIELLA OXYTOCA BLOOD 2024-07-29
#> 24: 5 KLEBSIELLA PNEUMONIAE BLOOD 2024-08-06
#> 25: 5 KLEBEIELLA OXYTOCA BLOOD 2024-08-19
#> ptid spec type specdate