camr_combine_redcap_checkboxes: Combine REDCap Checkbox Fields into one Column

camr_combine_redcap_checkboxesR Documentation

Combine REDCap Checkbox Fields into one Column

Description

Use this function within dplyr::mutate.

Usage

camr_combine_redcap_checkboxes(
  cols,
  fn_rename = function(x) str_remove(x, "^.*___"),
  fn_predicate = function(x) {
     if (!all(x %in% 0:1)) 
        
    stop("Specified columns are not all 0 or 1.")
     x == "1"
 },
  collapse = "|",
  as.factor = FALSE
)

Arguments

cols

Tidyselect expression.

fn_rename

Function with which to rename collapsed columns. Default removes the '___' prefix.

fn_predicate

Function which transforms each checkbox field value to TRUE/FALSE. Default is x == 1.

collapse

Character to separate collapsed values. Defaut is '|'.

as.factor

Create a factor where the levels are all the possible combinations of values. Default is FALSE.

Value

Character or factor vector of collapsed checkbox values.


rettopnivek/camrprojects documentation built on March 26, 2024, 9:17 a.m.