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

list_select Function Implementation #197

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions .github/workflows/recheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
workflow_dispatch:
inputs:
which:
type: choice
description: Which dependents to check
options:
- strong
- most

name: Reverse dependency check

jobs:
revdep_check:
name: Reverse check ${{ inputs.which }} dependents
uses: r-devel/recheck/.github/workflows/recheck.yml@v1
with:
which: ${{ inputs.which }}
4 changes: 2 additions & 2 deletions 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: 1.1.1
Version: 1.2.0
Authors@R: c(
person("Richard", "Hanna", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0009-0005-6496-8154")),
Expand Down Expand Up @@ -52,5 +52,5 @@ Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
15 changes: 15 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ S3method(tbl_sum,redcap_supertbl)
S3method(vec_ptype_abbr,redcap_supertbl)
export(add_skimr_metadata)
export(bind_tibbles)
export(combine_checkboxes)
export(extract_tibble)
export(extract_tibbles)
export(fmt_strip_field_embedding)
export(fmt_strip_html)
export(fmt_strip_trailing_colon)
export(fmt_strip_trailing_punct)
export(fmt_strip_whitespace)
export(list_select)
export(make_labelled)
export(read_redcap)
export(write_redcap_xlsx)
Expand All @@ -25,6 +27,7 @@ importFrom(checkmate,assert_data_frame)
importFrom(checkmate,check_character)
importFrom(checkmate,check_choice)
importFrom(checkmate,check_environment)
importFrom(checkmate,check_list)
importFrom(checkmate,check_logical)
importFrom(checkmate,expect_character)
importFrom(checkmate,expect_double)
Expand All @@ -40,6 +43,8 @@ importFrom(dplyr,"%>%")
importFrom(dplyr,across)
importFrom(dplyr,bind_rows)
importFrom(dplyr,case_when)
importFrom(dplyr,coalesce)
importFrom(dplyr,cur_column)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,if_any)
Expand All @@ -50,10 +55,13 @@ importFrom(dplyr,pull)
importFrom(dplyr,recode)
importFrom(dplyr,relocate)
importFrom(dplyr,rename)
importFrom(dplyr,right_join)
importFrom(dplyr,row_number)
importFrom(dplyr,rowwise)
importFrom(dplyr,select)
importFrom(dplyr,slice)
importFrom(dplyr,summarise)
importFrom(dplyr,ungroup)
importFrom(formattable,percent)
importFrom(lobstr,obj_size)
importFrom(lubridate,is.Date)
Expand All @@ -66,6 +74,7 @@ importFrom(purrr,discard)
importFrom(purrr,flatten_chr)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map2_chr)
importFrom(purrr,map_int)
importFrom(purrr,map_lgl)
importFrom(purrr,pluck)
Expand All @@ -80,6 +89,7 @@ importFrom(readr,parse_integer)
importFrom(readr,parse_logical)
importFrom(readr,parse_time)
importFrom(rlang,"!!!")
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(rlang,abort)
importFrom(rlang,as_closure)
Expand All @@ -95,6 +105,7 @@ importFrom(rlang,enexpr)
importFrom(rlang,enquo)
importFrom(rlang,env_poke)
importFrom(rlang,eval_tidy)
importFrom(rlang,expr)
importFrom(rlang,get_env)
importFrom(rlang,global_env)
importFrom(rlang,is_atomic)
Expand All @@ -103,6 +114,9 @@ importFrom(rlang,is_bare_list)
importFrom(rlang,is_installed)
importFrom(rlang,new_environment)
importFrom(rlang,quo_get_expr)
importFrom(rlang,quo_name)
importFrom(rlang,sym)
importFrom(rlang,syms)
importFrom(rlang,try_fetch)
importFrom(rlang,zap)
importFrom(stats,na.omit)
Expand All @@ -121,6 +135,7 @@ importFrom(tidyr,complete)
importFrom(tidyr,fill)
importFrom(tidyr,nest)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,separate_wider_delim)
importFrom(tidyr,unnest)
importFrom(tidyr,unnest_wider)
importFrom(tidyselect,all_of)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# REDCapTidieR 1.2.0

# REDCapTidieR 1.1.1 (development version)

Version 1.1.1
Expand Down
16 changes: 10 additions & 6 deletions R/REDCapTidieR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@
#' @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
#' expect_factor expect_logical check_list
#' @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
#' left_join mutate pull recode relocate rename right_join row_number rowwise
#' select slice summarise ungroup coalesce cur_column
#' @importFrom formattable percent
#' @importFrom lobstr obj_size
#' @importFrom lubridate is.difftime is.period is.POSIXt is.Date
#' @importFrom purrr compose map map2 map_int map_lgl pluck pmap_chr some pmap discard flatten_chr
#' @importFrom purrr compose map map2 map_int map_lgl pluck pmap_chr some pmap
#' discard flatten_chr map2_chr
#' @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
#' eval_tidy get_env global_env is_atomic is_bare_formula is_bare_list quo_name
#' is_installed new_environment quo_get_expr try_fetch zap as_label sym syms expr
#' :=
#' @importFrom stringi stri_split_fixed
#' @importFrom stringr str_detect str_replace str_replace_all str_squish str_trunc
#' str_trim str_ends
#' @importFrom tibble as_tibble is_tibble tibble
#' @importFrom tidyr complete fill pivot_wider nest unnest unnest_wider
#' @importFrom tidyr complete fill pivot_wider nest separate_wider_delim unnest
#' unnest_wider
#' @importFrom tidyselect all_of any_of ends_with eval_select everything
#' starts_with where
#' @importFrom vctrs vec_ptype_abbr vec_ptype
Expand Down
56 changes: 56 additions & 0 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ check_arg_is_logical <- wrap_checkmate(check_logical)
#' @rdname checkmate
check_arg_choices <- wrap_checkmate(check_choice)

#' @rdname checkmate
check_arg_is_list <- wrap_checkmate(check_list)

#' @rdname checkmate
check_arg_is_valid_token <- function(x,
arg = caller_arg(x),
Expand Down Expand Up @@ -659,3 +662,56 @@ check_extra_field_values_message <- function(extra_field_values, call = caller_e
values = values
)
}

#' @title
#' Check fields exist for checkbox combination
#'
#' @param fields Vector of character strings to check the length of
#' @param expr A quosure expression
#' @param call The calling environment to use in the error message
#'
#' @keywords internal
check_fields_exist <- function(fields, expr, call = caller_env()) {
expr <- quo_name(expr)

if (length(fields) == 0) {
msg <- c(
x = "No fields detected using `{expr}`.",
i = "Ensure that the column names specified in {.arg cols} match the columns in your data. Check for typos or use {.pkg tidyselect} helpers like {.code starts_with()}, `contains()`, etc." # nolint: line_length_linter
)

cli_abort(
msg,
class = c("missing_checkbox_fields", "REDCapTidieR_cond")
)
}
}


#' @title
#' Check fields are of checkbox field type
#'
#' @param metadata_tbl A metadata tibble from a supertibble
#' @param call The calling environment to use in the error message
#'
#' @keywords internal

check_fields_are_checkboxes <- function(metadata_tbl, call = caller_env()) {
non_checkboxes <- metadata_tbl %>%
filter(.data$field_type != "checkbox")

if (nrow(non_checkboxes) > 0) {
non_checkboxes <- non_checkboxes %>%
pull(.data$field_name)

msg <- c(
x = "Non-checkbox fields selected for {.code form_name}",
`!` = "The following fields returned as non-checkbox field types: {.code {non_checkboxes}}"
)

cli_abort(
msg,
class = c("non_checkbox_fields", "REDCapTidieR_cond")
)
}
}
Loading
Loading