WorldHealthOrganization / godataR

R package for easier interactions with the Go.Data API
Other
12 stars 2 forks source link

error received in some functions if there is 0 data to un-nest #19

Open sarahollis opened 1 year ago

sarahollis commented 1 year ago

@joshwlambert we have come across this issue before and not sure how to fix it... i.e. if no contacts have vaccines, an error is thrown when you try to run

cases_vacc_history_clean <- clean_case_vax_history(cases,language_tokens)

after i added at least 1 vaccine to a contact, it ran fine, but before i got this error:

> contacts_vacc_history_clean <- clean_contact_vax_history(contacts,language_tokens)
Error in `tbl_at_vars()`:
! Can't subset columns that don't exist.
✖ Column `vaccinesreceived_date` doesn't exist.
Run `rlang::last_trace()` to see where the error occurred.

it may not be always evident to the analyst what the data contains etc - so is there a way to insert into some of these functions as a safeguard that if there is no data, just proceed with an empty data frame or skip that function and move to the next?

cc @jamesfuller-cdc

jamesfuller-cdc commented 1 year ago

Would this just be a simple check with an if/else?