Skip to content

Commit

Permalink
Merge pull request #209 from CHOP-CGTInformatics/cran-1.2-prep
Browse files Browse the repository at this point in the history
CRAN 1.2 Prep
  • Loading branch information
rsh52 authored Oct 23, 2024
2 parents 5c4a7de + 335ecc9 commit 33d95e4
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 4,850 deletions.
1 change: 0 additions & 1 deletion .Rprofile

This file was deleted.

6 changes: 3 additions & 3 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ check_fields_are_checkboxes <- function(metadata_tbl, call = caller_env()) {
#' @title Check equal distinct values between two columns
#'
#' @description
#' Takes a dataframe and two columns and checks if [n_distinct()] of the second
#' Takes a dataframe and two columns and checks if `n_distinct` of the second
#' column is all unique based on grouping of the first column.
#'
#' @param data a dataframe
Expand All @@ -757,8 +757,8 @@ check_fields_are_checkboxes <- function(metadata_tbl, call = caller_env()) {
check_equal_col_summaries <- function(data, col1, col2, call = caller_env()) {
summary <- data %>%
summarise(
.by = {{ col1 }},
n = n_distinct({{ col2 }})
.by = col1,
n = n_distinct(col2)
)

total_n <- summary %>%
Expand Down
18 changes: 10 additions & 8 deletions R/combine_checkboxes.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#'
#' @param supertbl A supertibble generated by [read_redcap()]. Required.
#' @param tbl The `redcap_form_name` of the data tibble to extract. Required.
#' @param cols <[`tidy-select`][tidyr_tidy_select]> Checkbox columns to combine to
#' single column. Required.
#' @param cols Checkbox columns to combine to single column. Required.
#' @param names_prefix String added to the start of every variable name.
#' @param names_sep String to separate new column names from `names_prefix`.
#' @param names_glue Instead of `names_sep` and `names_prefix`, you can supply
Expand Down Expand Up @@ -192,23 +191,26 @@ get_metadata_spec <- function(metadata_tbl,
if (!is.null(names_glue)) {
# Similar to pivot_*, use of `names_glue` overrides use of names_prefix/sep
glue_env <- out %>%
select(.data$.value) %>%
mutate(.new_value = as.character(glue::glue_data(., names_glue))) %>% # nolint: object_usage_linter
select(.data$.value)

glue_env$.new_value <- as.character(glue::glue_data(glue_env, names_glue))

glue_env <- glue_env %>%
select(.data$.new_value)

out <- cbind(out, glue_env)
} else {
out <- out %>%
mutate(
.new_value = case_when(names_prefix != "" ~ paste(names_prefix, .value, sep = names_sep),
.new_value = case_when(names_prefix != "" ~ paste(names_prefix, .data$.value, sep = names_sep),
.default = paste(names_prefix, .data$.value, sep = "")
)
)
}

# Check that for each unique value of .value there is one unique value of .new_value
# May be removed in the future
check_equal_col_summaries(out, .value, .new_value) # nolint: object_usage_linter
check_equal_col_summaries(out, ".value", ".new_value") # nolint: object_usage_linter

# Make sure selection is checkbox metadata field type
check_fields_are_checkboxes(out)
Expand Down Expand Up @@ -257,11 +259,11 @@ replace_true <- function(col, col_name, metadata, raw_or_label) {
#' based on the overall data tibble cross referenced with a nested section of the
#' metadata tibble.
#'
#' [case_when()] logic helps determine whether the value is a coalesced singular
#' `case_when` logic helps determine whether the value is a coalesced singular
#' value or a user-specified one via `multi_value_label` or `values_fill`.
#'
#' @details
#' This function is used in conjunction with [pmap()].
#' This function is used in conjunction with `pmap()`.
#'
#' @keywords internal
#'
Expand Down
31 changes: 22 additions & 9 deletions R/read_redcap.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,24 @@ read_redcap <- function(redcap_uri,
db_data <- multi_choice_to_labels(db_data, db_metadata, raw_or_label)
}

# Longitudinal Arms Check and Cleaning Application ----
# Check if database supplied is longitudinal to determine appropriate function
# to use
is_longitudinal <- if ("redcap_event_name" %in% names(db_data)) {
TRUE
# Database structure checks and definitions ----
is_longitudinal <- "redcap_event_name" %in% names(db_data)
has_repeating_structure <- "redcap_repeat_instance" %in% names(db_data)
has_repeating_events <- if (is_longitudinal && has_repeating_structure) {
any(
is.na(db_data$redcap_repeat_instrument) &
!is.na(db_data$redcap_repeat_instance)
)
} else {
FALSE
}

if (is_longitudinal) {
repeat_event_types <- get_repeat_event_types(db_data)
repeat_event_types <- if (has_repeating_events) {
get_repeat_event_types(db_data)
} else {
NULL
}

linked_arms <- link_arms(
redcap_uri = redcap_uri,
Expand Down Expand Up @@ -453,11 +460,17 @@ add_metadata <- function(supertbl, db_metadata, redcap_uri, token, suppress_redc
#' @keywords internal

add_event_mapping <- function(supertbl, linked_arms, repeat_event_types) {
event_info <- linked_arms %>%
left_join(repeat_event_types, by = c("unique_event_name" = "redcap_event_name")) %>%
event_info <- linked_arms

if (!is.null(repeat_event_types)) {
event_info <- event_info %>%
left_join(repeat_event_types, by = c("unique_event_name" = "redcap_event_name"))
}

event_info <- event_info %>%
add_partial_keys(.data$unique_event_name) %>%
select(
redcap_form_name = "form", "redcap_event", "event_name", "redcap_arm", "arm_name", "repeat_type"
redcap_form_name = "form", "redcap_event", "event_name", "redcap_arm", "arm_name", any_of("repeat_type")
) %>%
nest(redcap_events = !"redcap_form_name")

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ knitr::opts_chunk$set(
[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/6845/badge)](https://bestpractices.coreinfrastructure.org/projects/6845)
<!-- badges: end -->

The REDCapTidieR package provides an elegant way to [import](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#import) data from a [REDCap](https://www.project-redcap.org/) [project](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#project) into an R environment. It builds upon the [REDCapR](https://ouhscbbmc.github.io/REDCapR/) package to query the [REDCap API](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#redcap-api) and then transforms the returned data into a set of [tidy](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#tidy) [tibbles](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#tibble).
The REDCapTidieR package provides an elegant way to [import](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#import) data from a [REDCap](https://projectredcap.org/) [project](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#project) into an R environment. It builds upon the [REDCapR](https://ouhscbbmc.github.io/REDCapR/) package to query the [REDCap API](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#redcap-api) and then transforms the returned data into a set of [tidy](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#tidy) [tibbles](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#tibble).

REDCapTidieR is especially useful for dealing with complex REDCap projects that are [longitudinal](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#longitudinal-project) or include [repeating](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#repeating) [instruments](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#instrument) or both.

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ status](https://www.r-pkg.org/badges/version/REDCapTidieR)](https://CRAN.R-proje
coverage](https://codecov.io/gh/CHOP-CGTInformatics/REDCapTidieR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/CHOP-CGTInformatics/REDCapTidieR?branch=main)
[![OpenSSF Best
Practices](https://bestpractices.coreinfrastructure.org/projects/6845/badge)](https://bestpractices.coreinfrastructure.org/projects/6845)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.06277/status.svg)](https://doi.org/10.21105/joss.06277)
<!-- badges: end -->

The REDCapTidieR package provides an elegant way to
[import](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#import)
data from a [REDCap](https://www.project-redcap.org/)
data from a [REDCap](https://projectredcap.org/)
[project](https://chop-cgtinformatics.github.io/REDCapTidieR/articles/glossary.html#project)
into an R environment. It builds upon the
[REDCapR](https://ouhscbbmc.github.io/REDCapR/) package to query the
Expand Down
38 changes: 12 additions & 26 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,27 @@

Thank you for taking the time to review this submission and please reach out to either Stephan Kadauke, Richard Hanna, or Ezra Porter for any questions, comments, or concerns.

This submission patches version 1.1.0 to fix a test failure introduced by an upcoming release of `labelled` 2.13.0. We have worked with the developer of `labelled` to ensure this patch resolves their reverse dependency check failures.
This submission for v1.2.0 adds new functionality, new documentation, and patches several minor bugs.

## New Features

There are no significant user-facing changes in this release.

`read_redcap(raw_or_label = "haven")` now correctly casts categorical data values to character when their type is not character or numeric. This is a constraint of labels from the `haven` package which `labelled` will be checking for explicitly in their new release.
The only new feature in this release is an analytics function that exists in a silo away from the rest of the core package.

## Test environments

1. Local macOS Ventura 13.6.5, R 4.2.4
2. R-hub
1. [Ubuntu 22.04.4 LTS, R-next, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/8650642187/job/23719620675)
2. [Ubuntu 22.04.4 LTS, R-release, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/8650642187/job/23719621223)
3. [Ubuntu 22.04.4 LTS, R-devel, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/8650642187/job/23719620358)
4. [Windows Server](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/8650642187/job/23719620965)
3. [win-builder](https://win-builder.r-project.org/V4B5Ar22pIf5/), development version.
4. [GiHub Actions](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions), Ubuntu 20.04.02 LTS
1. Local macOS Sonoma 14.6.1, R 4.4.0
2. R-hub
1. [Ubuntu 22.04.5 LTS, R-next, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11486785018/job/31969845126)
2. [Ubuntu 22.04.5 LTS, R-release, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11486785018/job/31969845814)
3. [Ubuntu 22.04.4 LTS, R-devel, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11486785018/job/31969845504)
4. [Microsoft Windows Server 2022, 10.0.20348](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11486785018/job/31969846106)
3. [win-builder](https://win-builder.r-project.org/OQCea7cbW815/), development version.
4. [GiHub Actions](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions), Ubuntu 20.04.05 LTS

## R CMD check results:

- 0 ERRORs or WARNINGs on any builds

- A NOTE is generated in win-builder resulting from the package maintainer email address changing relative to the last CRAN release. This is an artifact of a different email address than the package maintainer's being used for the submission to win-builder.

```
* checking CRAN incoming feasibility ... [14s] NOTE
Maintainer: 'Richard Hanna <porterej@chop.edu>'
New maintainer:
Richard Hanna <porterej@chop.edu>
Old maintainer(s):
Richard Hanna <richardshanna91@gmail.com>
```
- 0 ERRORs or WARNINGs on any builds

## Downstream Dependencies:

No downstream packages are affected. No packages depend/import/suggest REDCapTidieR. Results: <https://github.com/CHOP-CGTInformatics/REDCapTidieR/blob/main/revdep/cran.md>
All packages that depend/import/suggest REDCapTidieR pass the [Reverse dependency checks](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11486797194).
8 changes: 7 additions & 1 deletion inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ REDCapTidieR's
RStudio
Recode
Recoding
Stata
Supertibble
Supertibbles
TRUEs
Tibble
Tibble's
Tibbles
Expand All @@ -30,6 +32,7 @@ analytics
api
appendings
cli
de
dplyr
dropdown
edu
Expand All @@ -38,6 +41,7 @@ ggplot
gtsummary
https
httptest
interpretable
labelled
multiselection
nonrepeat
Expand All @@ -48,12 +52,15 @@ preprocess
recode
recoded
recodes
recoding
skimr
summarise
supertbl
supertibble
supertibble's
supertibbles
tableStyleLight
tbl
tibble
tibble's
tibbles
Expand All @@ -62,7 +69,6 @@ tidyverse
truefalse
undirected
unlabelled
wb
xlsx
yesno
2 changes: 1 addition & 1 deletion man/check_equal_col_summaries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/combine_checkboxes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/convert_checkbox_vals.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion paper/paper.bib
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ @Manual{redcapr_cit
author = {Will Beasley},
year = {2023},
url = {https://ouhscbbmc.github.io/REDCapR/},
note = {https://ouhscbbmc.github.io/REDCapR/, https://github.com/OuhscBbmc/REDCapR, https://www.ouhsc.edu/bbmc/, https://project-redcap.org},
note = {https://ouhscbbmc.github.io/REDCapR/, https://github.com/OuhscBbmc/REDCapR, https://www.ouhsc.edu/bbmc/, https://projectredcap.org},
}

@Manual{redcapapi_cit,
Expand Down
2 changes: 1 addition & 1 deletion paper/paper.html
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ <h4 class="date">XX November 2023</h4>
<div id="summary" class="section level1">
<h1>Summary</h1>
<p>Capturing and storing electronic data is integral in the research
world. <a href="https://www.project-redcap.org/">REDCap</a> <span class="citation">(Harris et al. 2009, 2019)</span> offers a secure web
world. <a href="https://projectredcap.org/">REDCap</a> <span class="citation">(Harris et al. 2009, 2019)</span> offers a secure web
application that lets users build databases and surveys with a robust
front-end interface that can support data of any type, including data
requiring compliance with standards for protected information.</p>
Expand Down
2 changes: 1 addition & 1 deletion paper/paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bibliography: paper.bib

# Summary

Capturing and storing electronic data is integral in the research world. [REDCap](https://www.project-redcap.org/) [@Harris2009; @Harris2019] offers a secure web application that lets users build databases and surveys with a robust front-end interface that can support data of any type, including data requiring compliance with standards for protected information.
Capturing and storing electronic data is integral in the research world. [REDCap](https://projectredcap.org/) [@Harris2009; @Harris2019] offers a secure web application that lets users build databases and surveys with a robust front-end interface that can support data of any type, including data requiring compliance with standards for protected information.

Many REDCap users use the R programming language [@r_cit] to extract and analyze their data. The [`REDCapR`](https://cran.r-project.org/web/packages/REDCapR/index.html) [@redcapr_cit] and [`redcapAPI`](https://cran.r-project.org/web/packages/redcapAPI/index.html) [@redcapapi_cit] packages allow R users to extract data directly into their programming environment. While this works well for simple REDCap databases, it becomes cumbersome for complex databases, because the REDCap API outputs a "block matrix"--a single table with varied granularity levels, which conflicts with the "tidy data" framework [@Wickham2014] that advocates for standardized data organization.

Expand Down
Loading

0 comments on commit 33d95e4

Please sign in to comment.