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

Fix supertibble label #179

Closed ezraporter closed 7 months ago

ezraporter commented 7 months ago

Description

This PR fixes a bug that was causing one of our error messages to print incorrectly. Since it required learning a bit about custom print methods I also added a customization to the header when our supertibbles print. Let me know if you think we should keep it.

Proposed Changes

Error Message Fix

Old

missing_col_supertbl <- tibble(redcap_data = list()) %>%
  as_supertbl()
make_labelled(missing_col_supertbl)
#> Error in `make_labelled()`:
#> ✖ You've supplied `<rdcp_spr[,1]>` for `supertbl` which is not a valid
#>   value
#> ! Must contain `supertbl$redcap_metadata`
#> ℹ `supertbl` must be a REDCapTidieR supertibble, generated using
#>   `read_redcap()`

New

#> Error in `make_labelled()`:
#> ✖ You've supplied `<suprtbl[,1]>` for `supertbl` which is not a valid
#>   value
#> ! Must contain `supertbl$redcap_metadata`
#> ℹ `supertbl` must be a REDCapTidieR supertibble, generated using
#>   `read_redcap()`

Custom Header

Old

read_redcap(Sys.getenv("REDCAP_URI"), Sys.getenv("REDCAPTIDIER_CLASSIC_API")) %>%
  suppressWarnings()
#> # A tibble: 9 × 9
#>   redcap_form_name       redcap_form_label redcap_data redcap_metadata structure
#>   <chr>                  <chr>             <list>      <list>          <chr>    
#> 1 nonrepeated            Nonrepeated       <tibble>    <tibble>        nonrepea…
#> 2 nonrepeated2           Nonrepeated2      <tibble>    <tibble>        nonrepea…
#> 3 repeated               Repeated          <tibble>    <tibble>        repeating
#> 4 data_field_types       Data Field Types  <tibble>    <tibble>        nonrepea…
#> 5 text_input_validation… Text Input Valid… <tibble>    <tibble>        nonrepea…
#> 6 api_no_access          API No Access     <tibble>    <tibble>        nonrepea…
#> 7 api_no_access_2        API No Access 2   <tibble>    <tibble>        nonrepea…
#> 8 survey                 Survey            <tibble>    <tibble>        nonrepea…
#> 9 repeat_survey          Repeat Survey     <tibble>    <tibble>        repeating
#> # ℹ 4 more variables: data_rows <int>, data_cols <int>, data_size <lbstr_by>,
#> #   data_na_pct <formttbl>

New

read_redcap(Sys.getenv("REDCAP_URI"), Sys.getenv("REDCAPTIDIER_CLASSIC_API")) %>%
  suppressWarnings()
#> # A REDCapTidieR Supertibble with 9 instruments
#>   redcap_form_name       redcap_form_label redcap_data redcap_metadata structure
#>   <chr>                  <chr>             <list>      <list>          <chr>    
#> 1 nonrepeated            Nonrepeated       <tibble>    <tibble>        nonrepea…
#> 2 nonrepeated2           Nonrepeated2      <tibble>    <tibble>        nonrepea…
#> 3 repeated               Repeated          <tibble>    <tibble>        repeating
#> 4 data_field_types       Data Field Types  <tibble>    <tibble>        nonrepea…
#> 5 text_input_validation… Text Input Valid… <tibble>    <tibble>        nonrepea…
#> 6 api_no_access          API No Access     <tibble>    <tibble>        nonrepea…
#> 7 api_no_access_2        API No Access 2   <tibble>    <tibble>        nonrepea…
#> 8 survey                 Survey            <tibble>    <tibble>        nonrepea…
#> 9 repeat_survey          Repeat Survey     <tibble>    <tibble>        repeating
#> # ℹ 4 more variables: data_rows <int>, data_cols <int>, data_size <lbstr_by>,
#> #   data_na_pct <formttbl>

Issue Addressed

Closes #157

PR Checklist

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

Code Review

This section to be used by the reviewer and developers during Code Review after PR submission

Code Review Checklist

skadauke commented 7 months ago

I think this looks awesome! One tiny thing: please capitalize the final R in REDCapTidieR. :)

rsh52 commented 7 months ago

Looks like the failure is a snapshot update which is expected.

The warnings weren't appearing for me but seem to be related to .data for a few instances I used in clean_redcap_long(). I think here:

https://github.com/CHOP-CGTInformatics/REDCapTidieR/blob/5ab694e76a7560e5aaebc0a7ef6237291f2a0581/R/clean_redcap_long.R#L87-L88

ezraporter commented 7 months ago

I think this looks awesome! One tiny thing: please capitalize the final R in REDCapTidieR. :)

Good catch!

ezraporter commented 7 months ago

Looks like the failure is a snapshot update which is expected.

The warnings weren't appearing for me but seem to be related to .data for a few instances I used in clean_redcap_long(). I think here:

https://github.com/CHOP-CGTInformatics/REDCapTidieR/blob/5ab694e76a7560e5aaebc0a7ef6237291f2a0581/R/clean_redcap_long.R#L87-L88

I think I fixed this in the last commit. I'll keep an eye on the CI. I went ahead and just upgraded everything in our renv.lock so package versions locally should be closer to what's running in CI.