Learn R Programming

REDCapCAST package

Casting metadata for REDCap database creation and handling of castellated data using repeated instruments and longitudinal projects in REDCap.

This is implemented with

  • An app-interface for easy database creation accessible here or available to run locally with shiny_cast() allowing you to easily create a REDCap database based on an existing spreadsheet.

  • Export data from REDCap in different formats handling castellated data, and on default only export requested data, this is mainly through read_redcap_tables().

REDCapCAST was initially build on, and still includes code from pegeler/REDCapRITS, and relies on functions from the REDCapR-project

History

This package was originally forked from pegeler/REDCapRITS. The REDCapRITS represents great and extensive work to handle castellated REDCap data in different programming languages. REDCapCAST has evolved into much more than just handling castellated data and so has been detatched from the original project while still relying on the main REDCap_split function. All access to the REDCap database is build on the outstanding work in REDCapR.

This package really started out of frustration during my PhD in health science hearing colleagues complaining about that "castellated" data formatting of REDCap exports when doing longitudinal projects and being used to wide data. This led to some bad decisions in building databases avoiding repeated instruments. This package solves these challenges, but solutions are also implemented else where like the redcapAPI or REDCapTidieR packages, which are bigger project.

To help new PhD students and other researchers, I have also worked on creating a few helper/wrapper-functions to ease data access. Documentation is on it's way.

For any more advanced uses, consider using the redcapAPI or REDCapR packages.

Future

The plan with this package is to be bundled with a Handbook on working with REDCap from R. This work is in progress but is limited by the time available. Please feel free to contact me or create and issue with ideas for future additions.

Installation and use

The package is available on CRAN. Install the latest version:

install.packages("REDCapCAST")

Install the latest version directly from GitHub:

require("remotes")
remotes::install_github("agdamsbo/REDCapCAST")

Launch the REDCapCAST app interface directly on your own machine:

REDCapCAST::shiny_cast()

Code of Conduct

Please note that the REDCapCAST project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('REDCapCAST')

Monthly Downloads

532

Version

25.3.1

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Andreas Gammelgaard Damsbo

Last Published

March 5th, 2025

Functions in REDCapCAST (25.3.1)

d2w

Convert single digits to words
char2choice

Simple function to generate REDCap choices from character vector
char2cond

Simple function to generate REDCap branching logic from character vector
is.labelled

Tests for multiple label classes
fct2num

Allows conversion of factor to numeric values preserving original levels
is_missing

Multi missing check
export_redcap_instrument

Creates zip-file with necessary content to manually add instrument to database
easy_redcap

Secure API key storage and data acquisition in one
doc2dd

Doc table to data dictionary - EARLY, DOCS MISSING
hms2character

Change "hms" to "character" for REDCap upload.
mark_complete

Completion marking based on completed upload
is_repeated_longitudinal

Test if repeatable or longitudinal
focused_metadata

focused_metadata
html_tag_wrap

Simple html tag wrapping for REDCap text formatting
fct_drop

Drop unused levels preserving label data
read_redcap_instrument

Convenience function to download complete instrument, using token storage in keyring.
nav_bar_page

Nav_bar defining function for shiny ui
named_levels

Get named vector of factor levels and values
guess_time_only_filter

Try at determining which are true time only variables
mtcars_redcap

mtcars dataset slightly modified to use for Shiny app upload demonstration
numchar2fct

Applying var2fct across data set
get_id_name

Get the id name
match_fields_to_form

Match fields to forms
guess_time_only

Guess time variables based on naming pattern
get_api_key

Retrieve project API key if stored, if not, set and retrieve
redcap_wider

Transforms list of REDCap data.frames to a single wide data.frame
read_redcap_tables

Download REDCap data
replace_curly_quote

Replace curly apostrophes and quotes from word
split_non_repeating_forms

Split a data frame into separate tables for each form
vec2choice

Named vector to REDCap choices (`wrapping compact_vec()`)
redcapcast_meta

REDCap metadata from data base
shiny_cast

Launch the included Shiny-app for database casting and upload
get_attr

Extract attribute. Returns NA if none
redcapcast_data

Data set for demonstration
haven_all_levels

Finish incomplete haven attributes substituting missings with values
process_user_input.data.frame

User input processing data.frame
process_user_input.default

User input processing default
process_user_input.character

User input processing character
process_user_input

User input processing
strsplitx

Extended string splitting
process_user_input.response

User input processing response
parse_data

Helper to auto-parse un-formatted data with haven and readr
read_input

Flexible file import based on extension
possibly_roman

Test if vector can be interpreted as roman numerals
possibly_numeric

Tests if vector can be interpreted as numeric without introducing NAs by coercion
var2fct

Convert vector to factor based on threshold of number of unique levels
time_only_correction

Correction based on time_only_filter function
sanitize_split

Sanitize list of data frames
suffix2label

Transfer variable name suffix to label in widened data
set_attr

Set attributes for named attribute. Appends if attr is NULL
all_na

Check if vector is all NA
case_match_regex_list

List-base regex case_when
as_logical

Interpret specific binary values as logicals
apply_field_label

Apply REDCap filed labels to data frame
REDCap_split

Split REDCap repeating instruments table into multiple tables
cast_data_overview

Overview of REDCapCAST data for shiny
apply_factor_labels

Preserve all factor levels from REDCap data dictionary in data export
cast_meta_overview

Overview of REDCapCAST meta data for shiny
as_factor

Convert labelled vectors to factors while preserving attributes
REDCapCAST-package

REDCapCAST: REDCap Metadata Casting and Castellated Data Handling
create_instrument_meta

DEPRICATED Create zips file with necessary content based on data set
cut_string_length

Cut string to desired length
clean_field_label

Very simple function to remove rich text formatting from field label and save the first paragraph ('<p>...</p>').
clean_redcap_name

clean_redcap_name
format_redcap_factor

Converts REDCap choices to factor levels and stores in labels attribute
ds2dd

(DEPRECATED) Data set to data dictionary function
ds2dd_detailed

Extract data from stata file for data dictionary
file_extension

DEPRECATED Helper to import files correctly
create_html_table

Create two-column HTML table for data piping in REDCap instruments
compact_vec

Compacting a vector of any length with or without names
format_subheader

Sub-header formatting wrapper