Turns the subject ID columns of all datasets into a factor containing levels for all the subjects of the database. Avoid problems when joining tables, and some checks can be performed on the levels.
Arguments
- database
an edc_database object, from
read_trialmaster()
or other EDCimport reading functions.- preprocess
an optional function to modify the subject ID column. Default to
as.numeric()
if applicable andidentity()
otherwise. See examples.- col_subjid
the names of the columns holding the subject ID (as character)
Examples
db = edc_example()
#> Warning: Option "edc_lookup" has been overwritten.
db$enrol = head(db$enrol, 10)
db$enrol$subjid %>% head()
#> [1] 1 2 3 4 5 6
db = edc_unify_subjid(db)
db$enrol$subjid %>% head()
#> [1] 1 2 3 4 5 6
#> 50 Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ... 50
db = edc_unify_subjid(db, preprocess=function(x) paste0("#", x))
db$enrol$subjid %>% head()
#> [1] #1 #2 #3 #4 #5 #6
#> 50 Levels: #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 ... #50