Skip to content

Commit

Permalink
Implement argument checking for exported functions (#114)
Browse files Browse the repository at this point in the history
* bind_tibbles() arg checking

* extract_tibble/s() arg checking

* read_redcap/make_labelled arg checking

* refactor checkmate checks

* Update test-read_redcap.R

* lint

* use call in cli_*()

* add check_arg_is_supertbl()

* add check_arg_is_valid_token

* use S3 class in check_arg_is_supertbl

* add superheroes_supertbl data for examples

* update error message

* update S3 class

* add example error messages
  • Loading branch information
ezraporter authored Dec 20, 2022
1 parent b38d5e7 commit dd35fa2
Show file tree
Hide file tree
Showing 34 changed files with 848 additions and 184 deletions.
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ importFrom(REDCapR,redcap_event_instruments)
importFrom(REDCapR,redcap_instruments)
importFrom(REDCapR,redcap_metadata_read)
importFrom(REDCapR,redcap_read_oneshot)
importFrom(REDCapR,sanitize_token)
importFrom(checkmate,assert_character)
importFrom(checkmate,assert_data_frame)
importFrom(checkmate,check_character)
importFrom(checkmate,check_choice)
importFrom(checkmate,check_environment)
importFrom(checkmate,check_logical)
importFrom(checkmate,expect_character)
importFrom(checkmate,expect_double)
importFrom(checkmate,expect_factor)
importFrom(checkmate,expect_logical)
importFrom(cli,cli_abort)
importFrom(cli,cli_vec)
importFrom(cli,cli_warn)
importFrom(dplyr,"%>%")
importFrom(dplyr,across)
Expand All @@ -50,17 +56,22 @@ importFrom(purrr,compose)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map_int)
importFrom(purrr,map_lgl)
importFrom(purrr,pluck)
importFrom(rlang,"!!!")
importFrom(rlang,.data)
importFrom(rlang,as_closure)
importFrom(rlang,as_label)
importFrom(rlang,caller_arg)
importFrom(rlang,caller_env)
importFrom(rlang,check_installed)
importFrom(rlang,current_env)
importFrom(rlang,enquo)
importFrom(rlang,env_poke)
importFrom(rlang,global_env)
importFrom(rlang,is_atomic)
importFrom(rlang,is_bare_formula)
importFrom(rlang,is_bare_list)
importFrom(rlang,new_environment)
importFrom(stringi,stri_split_fixed)
importFrom(stringr,str_detect)
Expand Down
16 changes: 8 additions & 8 deletions R/bind_tibbles.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@
#' @importFrom purrr map2 pluck
#'
#' @examples
#' \dontrun{
#' # Create an empty environment
#' my_env <- new.env()
#'
#' ls(my_env)
#'
#' # Mock up a supertibble
#' supertbl <- tibble::tribble(
#' ~redcap_form_name, ~redcap_data, ~structure,
#' "super_hero_powers", list(), "repeating",
#' "heroes_information", list(), "nonrepeating"
#' )
#' superheroes_supertbl
#'
#' bind_tibbles(supertbl, my_env)
#' bind_tibbles(superheroes_supertbl, my_env)
#'
#' ls(my_env)
#'
#'}
#' @export

bind_tibbles <- function(supertbl,
environment = global_env(),
tbls = NULL) {
check_arg_is_supertbl(supertbl, req_cols = "redcap_data")
check_arg_is_env(environment)
check_arg_is_character(tbls, null.ok = TRUE, any.missing = FALSE, min.len = 1)

# Name variables
my_supertbl <- supertbl

Expand Down
Loading

0 comments on commit dd35fa2

Please sign in to comment.