CHOP-CGTInformatics / REDCapTidieR

Makes it easy to read REDCap Projects into R
https://chop-cgtinformatics.github.io/REDCapTidieR/
Other
33 stars 8 forks source link

[BUG] Unexpected Warning Related to readr/vroom #121

Closed rsh52 closed 1 year ago

rsh52 commented 1 year ago

Expected Behavior

REDCapTidieR should provide useful/helpful error/warning messages.

Current Behavior

A warning came up when using REDCapTidieR on the CHOP BMT Outcomes REDCap Database:

Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
   dat <- vroom(...)
   problems(dat)

It's possible that our outstanding PRs to capture unexpected warnings will mask/resolve this, but we should look into the reason why this is occurring for two reasons:

Screenshots image

Checklist

Before submitting this issue, please check and verify below that the submission meets the below criteria:

rsh52 commented 1 year ago

So after a bit of digging, this seems to be a tunneled bug related to REDCapR and not our own package.

The rabbit hole

In redcap_read_oneshot there is a portion relying on readr::read_csv:

https://github.com/OuhscBbmc/REDCapR/blob/4ffb44c1bc57df94e97ef32b7d3e4fd91921a788/R/redcap-read-oneshot.R#L281-L290

And this in turn relies on a portion of vroom::vroom:

https://github.com/tidyverse/readr/blob/ee3fbae819a37f3a62cf4ce1c2a925ab12fe719f/R/read_delim.R#L286

Which causes a warning at a further nested vroom::vroom_:

https://github.com/tidyverse/vroom/blob/3d4b905b0db2114b0a99bbfc0813fdcc41fda621/R/cpp11.R#L59-L61


I was able to get vroom::problems() to work and give us an output:

probs
# A tibble: 1,060 × 5
     row   col expected           actual                               file                  
   <int> <int> <chr>              <chr>                                <chr>                 
 1    17    17 1/0/T/F/TRUE/FALSE 159961                               /private/var/folders/…
 2    18    37 1/0/T/F/TRUE/FALSE 2                                    /private/var/folders/…
 3    19    37 1/0/T/F/TRUE/FALSE 2                                    /private/var/folders/…
 4    50    38 1/0/T/F/TRUE/FALSE 3                                    /private/var/folders/…
 5    52    89 1/0/T/F/TRUE/FALSE 0.00                                 /private/var/folders/…
 6    52   185 1/0/T/F/TRUE/FALSE 3                                    /private/var/folders/…
 7    52   191 1/0/T/F/TRUE/FALSE 2                                    /private/var/folders/…
 8    52   208 1/0/T/F/TRUE/FALSE Triamcinolone, Fluocinolone          /private/var/folders/…
 9    52   255 1/0/T/F/TRUE/FALSE Fluocinolone ointment, Triamcinolone /private/var/folders/…
# … with 1,051 more rows
# ℹ Use `print(n = ...)` to see more rows

In total there are 163 unique cols that are producing the same clash with expected in the problems output. I tried looking for any common threads between the first few problems but didn't notice anything out of the ordinary, I'm not sure why vroom shows boolean expectations for these columns as they all seem to be correctly attributed to non-T/F REDCap var types.

rsh52 commented 1 year ago

Solution:

Add to current try_redcapr() to catch unexpected warning, give friendly message, provide original parent message.