GEMINI-Medicine / Rgemini

A custom R package that provides a variety of functions to perform data analyses with GEMINI data
https://gemini-medicine.github.io/Rgemini/
Other
3 stars 0 forks source link

Accept date-time inputs in both `character` and `POSIXct` format #76

Closed loffleraSMH closed 3 months ago

loffleraSMH commented 7 months ago

New Feature Request

Affected functions: Any functions using date-time variables

The above-mentioned functions currently do not work if a user preprocesses the date-time inputs with lubridate::ymd_hm() prior to running the function. Ideally, functions using date-time variables should check the format of the user-provided input, and only apply ymd_hm() if the input is of type character.

As an example, the icu_entry function runs fine when date-times are provided as characters:

icu_entry(cohort = data.table(genc_id = 1, admission_date_time = "2020-01-01 12:00"),
                ipscu = data.table(genc_id = 1, scu_admit_date_time = "2020-01-02 04:00", scu_unit_number = 30)
)

However, the function will return a warning that all "All formats failed to parse" if a user provides date-times in POSIXct/POSIXt format:

icu_entry(cohort = data.table(genc_id = 1, admission_date_time = lubridate::ymd_hm("2020-01-01 12:00")),
                ipscu = data.table(genc_id = 1, scu_admit_date_time = lubridate::ymd_hm("2020-01-02 04:00"), scu_unit_number = 30)
)

image

Given that many users will preprocess date-times prior to deriving additional variables, it would be useful to adapt the functions dealing with date-time variables to handle both character and POSIXct formats.

We should probably add this as a utility function that checks/converts date-times. This function can also produce a warning message for entries that don't have a time stamp (but only date). This would automatically also address issue #68.