Learn R Programming

⚠️There's a newer version (25.3.1) of this package.Take me there.

REDCapCAST package

REDCap database casting and handling of castellated data when using repeated instruments and longitudinal projects.

This package is a fork of pegeler/REDCapRITS. The REDCapRITS represents great and extensive work to handle castellated REDCap data in different programming languages. This fork is purely minded on R usage and includes a few implementations of the main REDCap_split function.

I started working on this project as the castellated longitudinal data set was a little challenging. Later, I have come to learn of the redcapAPI package, which would also cover this functionality. I find the redcapAPIpackage quite advanced and a little difficult to work with. This have led to the continued work on this package, as an easy-to-use approach for data migration, data base creation and data handling. This package is very much to be seen as an attempt at a R-to-REDCap-to-R foundry for handling both the transition from dataset/variable list to database and the other way, from REDCap database to a tidy dataset. The goal was also to allow for a "minimal data" approach by allowing to filter records, instruments and variables in the export to only download data needed. I think this approach is desirable for handling sensitive, clinical data. Please refer to REDCap-Tools for other great tools for working with REDCap in R.

For any more advanced uses, consider using the redcapAPI package.

Use and immprovements

Here is just a short description of the main functions:

  • REDcap_split(): Works largely as the original REDCapRITS::REDCap_split(). It takes a REDCap dataset and metadata (data dictionary) to split the data set into a list of dataframes of instruments.

  • read_redcap_tables(): wraps the use of REDCapR::redcap_read() with REDCap_split() to ease the export of REDCap data. Default output is a list of data frames with one data frame for each REDCap instrument.

  • redcap_wider(): joins and pivots a list of data frames with repeated instruments to a wide format utilizing the tidyr::pivot_wider() from the tidyverse.

  • easy_redcap(): combines secure API key storage with the keyring-package, focused data retrieval and optional widening. This is the recommended approach for easy data access and analysis.

  • ds2dd_detailed(): Converts a data set to a data dictionary for upload to a new REDCap database. Variables (fields) and instruments in a REDCap data base are defined by this data dictionary.

  • doc2dd(): Converts a document table to data dictionary. This allows to specify instrument or whole data dictionary in text document, which for most is easier to work with and easily modifiable. Very much like a easy version of just working directly in the data dictionary file itself.

  • shiny_cast(): Shiny application to ease the process of converting a spreadsheet/data set to a REDCap database. The app runs locally and data is transferred securely. You can just create and upload the data dictionary, but you can also transfer the given data in the same process. The app is hosted on shinyapps.io while I work on a shinylive implementation.

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

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")

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

24.10.3

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Andreas Gammelgaard Damsbo

Last Published

October 3rd, 2024

Functions in REDCapCAST (24.10.3)

get_api_key

Retrieve project API key if stored, if not, set and retrieve
process_user_input.response

User input processing response
process_user_input.data.frame

User input processing data.frame
ui_factory

UI factory for shiny app
redcap_wider

Redcap Wider
split_non_repeating_forms

Split a data frame into separate tables for each form
redcapcast_data

Data set for demonstration
read_redcap_instrument

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

Test if repeatable or longitudinal
server_factory

Shiny server factory
sanitize_split

Sanitize list of data frames
shiny_cast

Launch the included Shiny-app for database casting and upload
process_user_input.default

User input processing default
strsplitx

Extended string splitting
process_user_input.character

User input processing character
guess_time_only_filter

Try at determining which are true time only variables
read_redcap_tables

Download REDCap data
mark_complete

Completion marking based on completed upload
read_input

Flexible file import based on extension
time_only_correction

Correction based on time_only_filter function
get_id_name

Get the id name
process_user_input

User input processing
redcapcast_meta

REDCap metadata from data base
hms2character

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

Simple html tag wrapping for REDCap text formatting
is_missing

Multi missing check
replace_curly_quote

Replace curly apostrophes and quotes from word
char2cond

Simple function to generate REDCap branching logic from character vector
d2w

Convert single digits to words
char2choice

Simple function to generate REDCap choices from character vector
case_match_regex_list

List-base regex case_when
create_html_table

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

Doc table to data dictionary - EARLY, DOCS MISSING
create_instrument_meta

Create zips file with necessary content based on data set
clean_redcap_name

clean_redcap_name
REDCapCAST-package

REDCapCAST: REDCap Castellated Data Handling
REDCap_split

Split REDCap repeating instruments table into multiple tables
easy_redcap

Secure API key storage and data acquisition in one
format_subheader

Sub-header formatting wrapper
file_extension

Helper to import files correctly
focused_metadata

focused_metadata
ds2dd_detailed

Extract data from stata file for data dictionary
ds2dd

(DEPRECATED) Data set to data dictionary function
match_fields_to_form

Match fields to forms
mtcars_redcap

mtcars dataset slightly modified to use for Shiny app upload demonstration