Skip to content

Commit

Permalink
Merge pull request #163 from CHOP-CGTInformatics/minor-updates
Browse files Browse the repository at this point in the history
Minor Updates & Cleaning 🧹
  • Loading branch information
rsh52 authored Oct 23, 2023
2 parents 249a10c + 5e23a3c commit 71b4ecc
Show file tree
Hide file tree
Showing 24 changed files with 1,066 additions and 764 deletions.
3 changes: 1 addition & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ Before submitting this PR, please check and verify below that the submission mee

- [ ] New/revised functions have associated tests
- [ ] New/revised functions that update downstream outputs have associated static testing files (`.RDS`) updated under `inst/testdata/create_test_data.R`
- [ ] New tests that make API calls use `httptest::with_mock_api` and any new mocks were added to `tests/testthat/fixtures/create_httptest_mocks.R`
- [ ] New/revised functions use appropriate naming conventions
- [ ] New/revised functions don't repeat code
- [ ] Code changes are less than **250** lines total
- [ ] Issues linked to the PR using [GitHub's list of keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
- [ ] The appropriate reviewer is assigned to the PR
- [ ] The appropriate developers are assigned to the PR
- [ ] Pre-release package version incremented using `usethis::use_dev_version()`
- [ ] Pre-release package version incremented using `usethis::use_version()`

# Code Review
This section to be used by the reviewer and developers during Code Review after PR submission
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: REDCapTidieR
Type: Package
Title: Extract 'REDCap' Databases into Tidy 'Tibble's
Version: 0.4.1.9000
Version: 0.4.1.9001
Authors@R: c(
person("Richard", "Hanna", , "richardshanna91@gmail.com", role = c("aut", "cre")),
person("Stephan", "Kadauke", , "kadaukes@chop.edu", role = "aut"),
Expand Down
30 changes: 30 additions & 0 deletions R/REDCapTidieR-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' @keywords internal
#' @aliases REDCapTidieR-package
#' @importFrom checkmate assert_character assert_data_frame check_character
#' check_choice check_environment check_logical expect_character expect_double
#' expect_factor expect_logical
#' @importFrom cli cli_abort cli_fmt cli_text cli_vec cli_warn qty
#' @importFrom dplyr %>% across bind_rows case_when filter group_by if_any if_else
#' left_join mutate pull recode relocate rename row_number select slice summarise
#' @importFrom formattable percent
#' @importFrom lobstr obj_size
#' @importFrom lubridate is.difftime is.period
#' @importFrom purrr compose map map2 map_int map_lgl pluck pmap_chr some
#' @importFrom REDCapR redcap_arm_export redcap_event_instruments redcap_instruments
#' redcap_metadata_read redcap_read_oneshot sanitize_token
#' @importFrom rlang .data !!! abort as_closure caller_arg caller_env catch_cnd
#' check_installed cnd_muffle current_call current_env enexpr enquo env_poke
#' eval_tidy get_env global_env is_atomic is_bare_formula is_bare_list
#' is_installed new_environment quo_get_expr try_fetch zap as_label
#' @importFrom stringi stri_split_fixed
#' @importFrom stringr str_detect str_replace str_replace_all str_squish str_trunc
#' str_trim
#' @importFrom tibble as_tibble is_tibble tibble
#' @importFrom tidyr complete fill pivot_wider nest unnest unnest_wider
#' @importFrom tidyselect all_of any_of ends_with eval_select everything
#' starts_with where
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
4 changes: 0 additions & 4 deletions R/bind_tibbles.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#' @param tbls A vector of the `redcap_form_name`s of the data tibbles to bind to
#' the environment. Default is `NULL` which binds all data tibbles.
#'
#' @importFrom dplyr filter pull %>%
#' @importFrom rlang env_poke current_env new_environment global_env .data
#' @importFrom purrr map2 pluck
#'
#' @examples
#' \dontrun{
#' # Create an empty environment
Expand Down
50 changes: 0 additions & 50 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
#' @return
#' A helpful error message alerting the user to check their API privileges.
#'
#' @importFrom rlang .data caller_env
#' @importFrom dplyr filter select group_by summarise
#' @importFrom tidyr pivot_wider
#' @importFrom cli cli_warn cli_text cli_fmt qty cli_abort
#' @importFrom purrr pmap_chr
#'
#' @param db_data The REDCap database output generated by
#' \code{REDCapR::redcap_read_oneshot()$data}
#' @param db_metadata The REDCap metadata output generated by \code{REDCapR::redcap_metadata_read()$data}
Expand Down Expand Up @@ -103,10 +97,6 @@ check_user_rights <- function(db_data,
#' \code{REDCapR::redcap_read_oneshot()$data}
#' @param call the calling environment to use in the error message
#'
#' @importFrom dplyr %>% filter
#' @importFrom cli cli_abort
#' @importFrom rlang caller_env
#'
#' @keywords internal


Expand Down Expand Up @@ -174,9 +164,6 @@ check_repeat_and_nonrepeat <- function(db_data, call = caller_env()) {
#' \code{REDCapR::redcap_read_oneshot()$data}
#' @param call the calling environment to use in the error message
#'
#' @importFrom cli cli_abort
#' @importFrom rlang caller_env
#'
#' @keywords internal

check_redcap_populated <- function(db_data, call = caller_env()) {
Expand All @@ -202,9 +189,6 @@ check_redcap_populated <- function(db_data, call = caller_env()) {
#' @return
#' An error message listing the requested instruments that don't exist
#'
#' @importFrom cli cli_abort
#' @importFrom rlang caller_env
#'
#' @param db_metadata The metadata file read by
#' \code{REDCapR::redcap_metadata_read()}
#' @param forms The character vector of instrument names passed to
Expand All @@ -229,11 +213,6 @@ check_forms_exist <- function(db_metadata, forms, call = caller_env()) {
#' Check that all metadata tibbles within a supertibble contain
#' \code{field_name} and \code{field_label} columns
#'
#' @importFrom purrr map map_int
#' @importFrom dplyr %>% filter
#' @importFrom cli cli_abort
#' @importFrom rlang caller_arg
#'
#' @param supertbl a supertibble containing a \code{redcap_metadata} column
#' @param call the calling environment to use in the error message
#'
Expand Down Expand Up @@ -294,9 +273,6 @@ check_req_labelled_metadata_fields <- function(supertbl, call = caller_env()) {
#' @title
#' Check that parsed labels are not duplicated
#'
#' @importFrom cli cli_warn qty
#' @importFrom rlang caller_env
#'
#' @param parsed_labels_output a vector of parsed labels produced by `parse_labels()`
#' @param field_name the name of the field associated with the labels to use in the warning message
#' @param warn_stripped_text logical for whether to include a note about HTML tag stripping in the message
Expand Down Expand Up @@ -367,9 +343,6 @@ check_parsed_labels <- function(parsed_labels_output,
#' @title
#' Check an argument with checkmate
#'
#' @importFrom cli cli_abort
#' @importFrom rlang caller_arg
#'
#' @param x An object to check
#' @param arg The name of the argument to include in an error message. Captured
#' by `rlang::caller_arg()` by default
Expand All @@ -386,8 +359,6 @@ check_parsed_labels <- function(parsed_labels_output,
NULL

# Function factory to wrap checkmate functions
#' @importFrom rlang caller_arg caller_env
#' @importFrom cli cli_abort
#' @noRd
wrap_checkmate <- function(f) {
error_class <- caller_arg(f)
Expand All @@ -411,9 +382,6 @@ wrap_checkmate <- function(f) {
}

#' @rdname checkmate
#' @importFrom cli cli_abort
#' @importFrom rlang caller_env caller_arg is_bare_list
#' @importFrom purrr map_lgl
check_arg_is_supertbl <- function(x,
req_cols = c("redcap_data", "redcap_metadata"),
arg = caller_arg(x),
Expand Down Expand Up @@ -471,25 +439,18 @@ check_arg_is_supertbl <- function(x,
}

#' @rdname checkmate
#' @importFrom checkmate check_environment
check_arg_is_env <- wrap_checkmate(check_environment)

#' @rdname checkmate
#' @importFrom checkmate check_character
check_arg_is_character <- wrap_checkmate(check_character)

#' @rdname checkmate
#' @importFrom checkmate check_logical
check_arg_is_logical <- wrap_checkmate(check_logical)

#' @rdname checkmate
#' @importFrom checkmate check_choice
check_arg_choices <- wrap_checkmate(check_choice)

#' @rdname checkmate
#' @importFrom REDCapR sanitize_token
#' @importFrom cli cli_abort
#' @importFrom rlang caller_arg caller_env try_fetch
check_arg_is_valid_token <- function(x,
arg = caller_arg(x),
call = caller_env()) {
Expand Down Expand Up @@ -519,9 +480,6 @@ check_arg_is_valid_token <- function(x,
#' If x is atomic, x with cli formatting to truncate to 5 values. Otherwise,
#' a string summarizing x produced by as_label
#'
#' @importFrom rlang as_label is_atomic
#' @importFrom cli cli_vec
#'
#' @keywords internal
format_error_val <- function(x) {
if (is_atomic(x)) {
Expand All @@ -533,8 +491,6 @@ format_error_val <- function(x) {
}

#' @rdname checkmate
#' @importFrom cli cli_warn
#' @importFrom rlang caller_arg caller_env
check_arg_is_valid_extension <- function(x,
valid_extensions,
arg = caller_arg(x),
Expand Down Expand Up @@ -581,9 +537,6 @@ check_arg_is_valid_extension <- function(x,
#' @return
#' An error message saying the requested data does not exist
#'
#' @importFrom cli cli_abort
#' @importFrom rlang caller_env
#'
#' @param db_data The REDCap database output generated by
#' \code{REDCapR::redcap_read_oneshot()$data}
#' @param col The column to check for in `redcap_data`
Expand Down Expand Up @@ -626,9 +579,6 @@ check_data_arg_exists <- function(db_data, col, arg, call = caller_env()) {
#' @return
#' An error message saying the requested file already exists
#'
#' @importFrom cli cli_abort
#' @importFrom rlang caller_env
#'
#' @param file The file that is being checked
#' @param overwrite Whether the file was declared to be overwritten
#' @param call The calling environment to use in the error message
Expand Down
18 changes: 0 additions & 18 deletions R/clean_redcap.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
#' can access dataframes under the \code{redcap_data} column with reference to
#' \code{form_name} and \code{structure} column details.
#'
#' @importFrom
#' checkmate assert_data_frame expect_logical expect_factor expect_character
#' expect_double
#' @importFrom dplyr filter pull
#' @importFrom purrr map
#' @importFrom tibble tibble
#' @importFrom rlang .data
#'
#' @keywords internal

clean_redcap <- function(db_data,
Expand Down Expand Up @@ -108,11 +100,6 @@ clean_redcap <- function(db_data,
#' @param db_metadata The REDCap metadata output defined by
#' \code{REDCapR::redcap_metadata_read()$data}
#'
#' @importFrom dplyr filter pull select relocate rename
#' @importFrom tidyselect all_of everything starts_with any_of
#' @importFrom tibble tibble
#' @importFrom rlang .data
#'
#' @keywords internal

distill_nonrepeat_table <- function(form_name,
Expand Down Expand Up @@ -203,11 +190,6 @@ distill_nonrepeat_table <- function(form_name,
#' @param db_metadata The non-longitudinal REDCap metadata output defined by
#' \code{REDCapR::redcap_metadata_read()$data}
#'
#' @importFrom dplyr filter pull select relocate rename
#' @importFrom tidyselect all_of everything starts_with any_of
#' @importFrom tibble tibble
#' @importFrom rlang .data
#'
#' @keywords internal

distill_repeat_table <- function(form_name,
Expand Down
17 changes: 0 additions & 17 deletions R/clean_redcap_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
#' can access dataframes under the \code{redcap_data} column with reference to
#' \code{form_name} and \code{structure} column details.
#'
#' @importFrom checkmate assert_data_frame
#' @importFrom dplyr filter pull
#' @importFrom purrr map
#' @importFrom tibble tibble
#' @importFrom rlang .data
#'
#' @keywords internal

clean_redcap_long <- function(db_data_long,
Expand Down Expand Up @@ -118,12 +112,6 @@ clean_redcap_long <- function(db_data_long,
#' @param linked_arms Output of \code{link_arms}, linking instruments to REDCap
#' events/arms
#'
#' @importFrom dplyr filter pull select relocate rename
#' @importFrom tidyselect all_of everything any_of
#' @importFrom tibble tibble
#' @importFrom stringr str_detect
#' @importFrom rlang .data
#'
#' @keywords internal

distill_nonrepeat_table_long <- function(form_name,
Expand Down Expand Up @@ -248,11 +236,6 @@ distill_nonrepeat_table_long <- function(form_name,
#' @param linked_arms Output of \code{link_arms}, linking instruments to REDCap
#' events/arms
#'
#' @importFrom dplyr filter pull select relocate rename
#' @importFrom tidyselect all_of everything any_of
#' @importFrom tibble tibble
#' @importFrom stringr str_detect
#' @importFrom rlang .data
#' @keywords internal

distill_repeat_table_long <- function(form_name,
Expand Down
40 changes: 0 additions & 40 deletions R/dev_utils.R
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
#' Retrieve credentials for creating or using mocks
#'
#' @param credentials names of credentials to retrieve. By default all credentials in
#' `inst/misc/fake_credentials.csv` are retrieved
#' @param fake logical. Should fake credentials be retrieved? By default `FALSE`
#'
#' @return
#' A named list of credentials from with `Sys.getenv()` if `fake = FALSE`
#' or from `inst/misc/fake_credentials.csv` if `fake = TRUE`
#' @keywords internal
get_credentials <- function(credentials = NULL, fake = FALSE) {
creds <- readr::read_csv(
system.file("misc/fake_credentials.csv", package = "REDCapTidieR"),
col_types = "cc"
)

if (!is.null(credentials)) {
if (!all(credentials %in% creds$name)) {
missing_creds <- setdiff(credentials, creds$name) # nolint: object_usage_linter
cli::cli_abort(c(
"x" = "{.code {missing_creds}} {?is/are} missing from {.path inst/misc/fake_credentials.csv}"
))
}

creds <- creds[creds$name %in% credentials, ]
}

res <- rep("", nrow(creds))

if (fake) {
res <- creds$value
} else {
res <- unname(Sys.getenv(creds$name))
}

res <- as.list(res)
names(res) <- creds$name
res
}

#' @title Additional release questions
#'
#' @description
Expand Down
9 changes: 0 additions & 9 deletions R/extract_tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
#' @param supertbl A supertibble generated by `read_redcap()`. Required.
#' @param tbl The `redcap_form_name` of the data tibble to extract. Required.
#'
#' @importFrom checkmate assert_character
#' @importFrom tidyselect all_of
#'
#' @examples
#' superheroes_supertbl
#'
Expand Down Expand Up @@ -55,12 +52,6 @@ extract_tibble <- function(supertbl,
#' @param tbls A vector of `form_name`s or a tidyselect helper. Default is
#' `dplyr::everything()`.
#'
#' @importFrom rlang enquo
#' @importFrom dplyr select %>%
#' @importFrom tidyselect eval_select everything
#' @importFrom tidyr pivot_wider
#' @importFrom purrr map pluck
#'
#' @examples
#' superheroes_supertbl
#'
Expand Down
Loading

0 comments on commit 71b4ecc

Please sign in to comment.