Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

recodeCheck

Change labelling of checkbox variables


Description

Rewrites the labelling of checkbox variables from Checked/Unchecked to Yes/No (or some other user-specified labelling).

Usage

recodeCheck(
  df,
  vars,
  old = c("Unchecked", "Checked"),
  new = c("No", "Yes"),
  reverse = FALSE
)

Arguments

df

A data frame, presumably retrieved from REDCap, though not a strict requirement.

vars

Optional character vector of variables to convert. If left missing, all of the variables in df that are identified as checkbox variables are relabelled. See 'Details' for more about identifying checkbox variables.

old

A character vector to be passed to factor. This indicates the levels to be replaced and their order.

new

A character vector of labels to replace the values in levels. The first value becomes the reference value.

reverse

For convenience, if the user would prefer to reverse the order of the elements in levels and labels, simply set this to TRUE.

Details

checkbox variables are not identified using the metadata from the REDCap database. Instead, variables are scanned, and those variables in which every value is in levels are assumed to be checkbox variables.

Realistically, this could be used to relabel any set of factors with identical labels, regardless of the data source. The number of labels is not limited, but levels and labels should have the same length.

The actual code to perform this is not particularly difficult (df[checkbox] <- lapply(df[checkbox], factor, levels=levels, labels=labels)), but checkbox variables are common enough in REDCap (and the Checked/Unchecked scheme so unpalatable) that a quick way to replace the labels was highly desirable

Author(s)

Benjamin Nutter


redcapAPI

Interface to 'REDCap'

v2.3
GPL-2
Authors
Benjamin Nutter [aut, ctb, cre], Stephen Lane [ctb], Will Beasley [ctb], Jeffrey Horner [ctb], Will Gray [ctb], Jeremy Stephens [ctb], Marcus Lehr [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.