diff --git a/NEWS.md b/NEWS.md index 8753513c..65d53cd4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,10 @@ +# REDCapTidieR (development version) + # REDCapTidieR 1.1.0 - `read_redcap()` now supports instruments that follow a mixed repeating/non-repeating structure with the `allow_mixed_structure` parameter - When enabled, instruments with mixed repeating/nonrepeating structure will be treated as single-instance repeating instruments +- A new metadata column, `form_complete_pct`, is now available when viewing the supertibble showing the percentage of a given instrument that has a form status marked as "Complete" (green) # REDCapTidieR 1.0.0 diff --git a/R/read_redcap.R b/R/read_redcap.R index a50b6ebf..83049b22 100644 --- a/R/read_redcap.R +++ b/R/read_redcap.R @@ -429,7 +429,7 @@ add_metadata <- function(supertbl, db_metadata, redcap_uri, token, suppress_redc unnest_wider(summary) %>% relocate( "redcap_form_name", "redcap_form_label", "redcap_data", "redcap_metadata", - "structure", "data_rows", "data_cols", "data_size", "data_na_pct" + "structure", "data_rows", "data_cols", "data_size", "data_na_pct", "form_complete_pct" ) } @@ -488,9 +488,13 @@ calc_metadata_stats <- function(data) { is.na() %>% mean() + form_complete_pct <- data %>% + summarise(avg_complete = mean(.data$form_status_complete == 2)) + list( data_rows = nrow(data), data_cols = ncol(data), data_size = obj_size(data), - data_na_pct = percent(na_pct, digits = 2, format = "fg") + data_na_pct = percent(na_pct, digits = 2, format = "fg"), + form_complete_pct = percent(form_complete_pct, digits = 2, format = "fg") ) } diff --git a/R/write.R b/R/write.R index 9a2baa18..9ad174c7 100644 --- a/R/write.R +++ b/R/write.R @@ -349,7 +349,7 @@ add_supertbl_toc <- function(wb, select(-any_of(c("redcap_data", "redcap_metadata", "redcap_events"))) %>% # Necessary to avoid "Number stored as text" Excel dialogue warnings mutate( - across(any_of("data_na_pct"), convert_percent), + across(any_of(c("data_na_pct", "form_complete_pct")), convert_percent), across(any_of("data_size"), ~ prettyunits::pretty_bytes(as.numeric(.))) ) diff --git a/man/figures/write_xlsx_default.png b/man/figures/write_xlsx_default.png index fcd1dcf5..48097012 100644 Binary files a/man/figures/write_xlsx_default.png and b/man/figures/write_xlsx_default.png differ diff --git a/tests/testthat/_snaps/write.md b/tests/testthat/_snaps/write.md index 7c011037..d77388fc 100644 --- a/tests/testthat/_snaps/write.md +++ b/tests/testthat/_snaps/write.md @@ -29,18 +29,18 @@ 10 nonrepeating 4 9 11 repeating 3 10 12 - Data size in Memory % of Data Missing Sheet # - 2 data_size data_na_pct Sheet # - 3 2.28 kB 0.25 1 - 4 1.94 kB 0.5 2 - 5 2.58 kB 0 3 - 6 7.71 kB 0.293103448275862 4 - 7 7.40 kB 0.75 5 - 8 1.78 kB 1 6 - 9 2.06 kB 1 7 - 10 3.73 kB 0.392857142857143 8 - 11 3.94 kB 0.142857142857143 9 - 12 10 + Data size in Memory % of Data Missing NA Sheet # + 2 data_size data_na_pct form_complete_pct Sheet # + 3 2.28 kB 0.25 0 1 + 4 1.94 kB 0.5 0 2 + 5 2.58 kB 0 0 3 + 6 7.71 kB 0.293103448275862 0 4 + 7 7.40 kB 0.75 0 5 + 8 1.78 kB 1 0 6 + 9 2.06 kB 1 0 7 + 10 3.73 kB 0.392857142857143 0 8 + 11 3.94 kB 0.142857142857143 0 9 + 12 10 [[1]][[2]] Record ID Text Box Input Text Box Input REDCap Instrument Completed? @@ -1589,7 +1589,7 @@ [[2]] tab_name tab_sheet tab_ref - 1 Table1 1 A2:H12 + 1 Table1 1 A2:I12 2 Table2 2 A2:D6 3 Table3 3 A2:D6 4 Table4 4 A2:E6 @@ -1601,7 +1601,7 @@ 10 Table10 10 A2:J5 11 Table11 11 A2:AZ68 tab_xml - 1
+ 1
2
3
4
diff --git a/tests/testthat/test-read_redcap.R b/tests/testthat/test-read_redcap.R index 3b34e15d..a845c0b4 100644 --- a/tests/testthat/test-read_redcap.R +++ b/tests/testthat/test-read_redcap.R @@ -260,7 +260,7 @@ test_that("read_redcap returns metadata", { expected_cols <- c( "redcap_form_name", "redcap_form_label", "redcap_data", "redcap_metadata", "redcap_events", "structure", "data_rows", "data_cols", "data_size", - "data_na_pct" + "data_na_pct", "form_complete_pct" ) # metadata fields exist and correctly ordered @@ -279,6 +279,9 @@ test_that("read_redcap returns metadata", { expect_true( all(out$data_na_pct >= 0) && all(out$data_na_pct <= 100) ) + expect_true( + all(out$form_complete_pct >= 0) && all(out$form_complete_pct <= 100) + ) # check that for each tibble in out$redcap_data, all fields in the data are # represented in the corresponding tibble in out$redcap_metadata