Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRAN 1.2 Prep #209

Merged
merged 11 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
34 changes: 10 additions & 24 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 in 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
1. Local macOS Sonoma 14.6.1, R 4.4.0
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. [Ubuntu 22.04.5 LTS, R-next, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11371750216/job/31634537921)
2. [Ubuntu 22.04.5 LTS, R-release, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11371750216/job/31634538851)
3. [Ubuntu 22.04.4 LTS, R-devel, GCC](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11371750216/job/31634538452)
4. [Microsoft Windows Server 2022, 10.0.20348](https://github.com/CHOP-CGTInformatics/REDCapTidieR/actions/runs/11371750216/job/31634539238)
3. [win-builder](https://win-builder.r-project.org/zPkjljy8Z67c/), 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 <[email protected]>'

New maintainer:
Richard Hanna <[email protected]>
Old maintainer(s):
Richard Hanna <[email protected]>
```

## 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>

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.

1 change: 0 additions & 1 deletion tests/testthat/test-read_redcap.R
Original file line number Diff line number Diff line change
Expand Up @@ -680,5 +680,4 @@ test_that("get_repeat_event_types() works", {
)

expect_equal(out, expected_out)

})
47 changes: 22 additions & 25 deletions utility/cli_message_examples_reprex.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ read_redcap(letters[1:3], classic_token)
read_redcap("https://www.google.com", classic_token)
#> Error in `read_redcap()`:
#> ✖ The REDCapR export operation was not successful.
#> ! An unexpected error occured.
#> ℹ This means that you probably discovered a bug!
#> ℹ Please consider submitting a bug report here:
#> <https://github.com/CHOP-CGTInformatics/REDCapTidieR/issues>.
#> Caused by error in `redcap_metadata_read()`:
#> ! The REDCapR metadata export operation was not successful. The error message was:
#> <html><body><h1>404 Not Found</h1></body></html>
#> ! The URL returned the HTTP error code 405 (POST Method not allowed).
#> ℹ Are you sure the URI points to an active REDCap API endpoint?
#> ℹ URI: `https://www.google.com`

read_redcap("https://www.google.comm", classic_token)
#> Error in `read_redcap()`:
Expand All @@ -63,13 +59,13 @@ read_redcap(redcap_uri, letters[1:3])

read_redcap(redcap_uri, "")
#> Error in `read_redcap()`:
#> ✖ The token is an empty string, not a valid 32-character hexademical
#> value.
#> ✖ The token is an empty string, which is not allowed.
#> ℹ API token: ``

read_redcap(redcap_uri, "CC0CE44238EF65C5DA26A55DD749AF7") # 31 hex characters
#> Error in `read_redcap()`:
#> ✖ The token is not a valid 32-character hexademical value.
#> ✖ The token does not conform with the regex
#> `^([0-9A-Fa-f]{32})(?:\n)?$`.
#> ℹ API token: `CC0CE44238EF65C5DA26A55DD749AF7`

read_redcap(redcap_uri, "CC0CE44238EF65C5DA26A55DD749AF7A") # will be rejected by server
Expand Down Expand Up @@ -259,7 +255,7 @@ withr::with_tempdir({
})
#> Error:
#> ✖ File
#> ''/private/var/folders/9c/k1m0bzys7gb1v32g86hfn5sn5k86h1/T/Rtmp1QPC0p/file5c744dd73619/temp.csv''
#> ''/private/var/folders/qc/mmjjyjq50530z9r_7mfqcqfhxkkk67/T/Rtmph4LQ3Z/filee5aa7b9bea48/temp.csv''
#> already exists.
#> ℹ Overwriting files is disabled by default. Set `overwrite = TRUE` to overwrite
#> existing file.
Expand Down Expand Up @@ -300,25 +296,26 @@ withr::with_tempdir({
write_redcap_xlsx(file = filepath)
})
#> Warning in write_redcap_xlsx(., file = filepath): ! No extension provided for `file`:
#> '/private/var/folders/9c/k1m0bzys7gb1v32g86hfn5sn5k86h1/T/Rtmp1QPC0p/file5c7456597c2b/temp'
#> '/private/var/folders/qc/mmjjyjq50530z9r_7mfqcqfhxkkk67/T/Rtmph4LQ3Z/filee5aa11455c98/temp'
#> ℹ The extension '.xlsx' will be appended to the file name.

# Printed supertibble

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
#> # A REDCapTidieR Supertibble with 10 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_validatio… 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
#> 10 labelled_vignette Labelled Vignette <tibble> <tibble> nonrepea…
#> # ℹ 5 more variables: data_rows <int>, data_cols <int>, data_size <lbstr_by>,
#> # data_na_pct <formttbl>, form_complete_pct <formttbl>

Expand All @@ -343,4 +340,4 @@ read_redcap(redcap_uri, Sys.getenv("REDCAPTIDIER_MDC_API"))
#> # data_na_pct <formttbl>, form_complete_pct <formttbl>
```

<sup>Created on 2024-04-10 with [reprex v2.1.0](https://reprex.tidyverse.org)</sup>
<sup>Created on 2024-10-16 with [reprex v2.1.0](https://reprex.tidyverse.org)</sup>
Loading
Loading