mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2025-12-16 17:42:10 +01:00
246 lines
13 KiB
Text
246 lines
13 KiB
Text
|
|
# 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](https://agdamsbo.shinyapps.io/redcapcast/) or available to run
|
|||
|
|
locally with
|
|||
|
|
[`shiny_cast()`](https://agdamsbo.github.io/REDCapCAST/reference/shiny_cast.md)
|
|||
|
|
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()`](https://agdamsbo.github.io/REDCapCAST/reference/read_redcap_tables.md).
|
|||
|
|
|
|||
|
|
REDCapCAST was initially build on, and still includes code from
|
|||
|
|
[pegeler/REDCapRITS](https://github.com/pegeler/REDCapRITS), and relies
|
|||
|
|
on functions from the
|
|||
|
|
[`REDCapR`](https://ouhscbbmc.github.io/REDCapR/)-project
|
|||
|
|
|
|||
|
|
## History
|
|||
|
|
|
|||
|
|
This package was originally forked from
|
|||
|
|
[pegeler/REDCapRITS](https://github.com/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`](#id_0).
|
|||
|
|
|
|||
|
|
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](https://github.com/vubiostat/redcapAPI) or
|
|||
|
|
[REDCapTidieR](https://github.com/CHOP-CGTInformatics/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`](https://github.com/vubiostat/redcapAPI) or
|
|||
|
|
[`REDCapR`](https://ouhscbbmc.github.io/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](https://agdamsbo.github.io/REDCapCAST/CODE_OF_CONDUCT.html). By
|
|||
|
|
contributing to this project, you agree to abide by its terms.
|
|||
|
|
|
|||
|
|
# Package index
|
|||
|
|
|
|||
|
|
## All functions
|
|||
|
|
|
|||
|
|
- [`REDCap_split()`](https://agdamsbo.github.io/REDCapCAST/reference/REDCap_split.md)
|
|||
|
|
: Split REDCap repeating instruments table into multiple tables
|
|||
|
|
- [`all_na()`](https://agdamsbo.github.io/REDCapCAST/reference/all_na.md)
|
|||
|
|
: Check if vector is all NA
|
|||
|
|
- [`apply_factor_labels()`](https://agdamsbo.github.io/REDCapCAST/reference/apply_factor_labels.md)
|
|||
|
|
: Preserve all factor levels from REDCap data dictionary in data
|
|||
|
|
export
|
|||
|
|
- [`apply_field_label()`](https://agdamsbo.github.io/REDCapCAST/reference/apply_field_label.md)
|
|||
|
|
: Apply REDCap filed labels to data frame
|
|||
|
|
- [`as_factor()`](https://agdamsbo.github.io/REDCapCAST/reference/as_factor.md)
|
|||
|
|
: Convert labelled vectors to factors while preserving attributes
|
|||
|
|
- [`as_logical()`](https://agdamsbo.github.io/REDCapCAST/reference/as_logical.md)
|
|||
|
|
: Interpret specific binary values as logicals
|
|||
|
|
- [`case_match_regex_list()`](https://agdamsbo.github.io/REDCapCAST/reference/case_match_regex_list.md)
|
|||
|
|
: List-base regex case_when
|
|||
|
|
- [`cast_data_overview()`](https://agdamsbo.github.io/REDCapCAST/reference/cast_data_overview.md)
|
|||
|
|
: Overview of REDCapCAST data for shiny
|
|||
|
|
- [`cast_meta_overview()`](https://agdamsbo.github.io/REDCapCAST/reference/cast_meta_overview.md)
|
|||
|
|
: Overview of REDCapCAST meta data for shiny
|
|||
|
|
- [`char2choice()`](https://agdamsbo.github.io/REDCapCAST/reference/char2choice.md)
|
|||
|
|
: Simple function to generate REDCap choices from character vector
|
|||
|
|
- [`char2cond()`](https://agdamsbo.github.io/REDCapCAST/reference/char2cond.md)
|
|||
|
|
: Simple function to generate REDCap branching logic from character
|
|||
|
|
vector
|
|||
|
|
- [`clean_field_label()`](https://agdamsbo.github.io/REDCapCAST/reference/clean_field_label.md)
|
|||
|
|
: Very simple function to remove rich text formatting from field label
|
|||
|
|
and save the first paragraph ('\<p\>...\</p\>').
|
|||
|
|
- [`clean_redcap_name()`](https://agdamsbo.github.io/REDCapCAST/reference/clean_redcap_name.md)
|
|||
|
|
: clean_redcap_name
|
|||
|
|
- [`compact_vec()`](https://agdamsbo.github.io/REDCapCAST/reference/compact_vec.md)
|
|||
|
|
: Compacting a vector of any length with or without names
|
|||
|
|
- [`create_html_table()`](https://agdamsbo.github.io/REDCapCAST/reference/create_html_table.md)
|
|||
|
|
: Create two-column HTML table for data piping in REDCap instruments
|
|||
|
|
- [`create_instrument_meta()`](https://agdamsbo.github.io/REDCapCAST/reference/create_instrument_meta.md)
|
|||
|
|
: DEPRICATED Create zips file with necessary content based on data set
|
|||
|
|
- [`cut_string_length()`](https://agdamsbo.github.io/REDCapCAST/reference/cut_string_length.md)
|
|||
|
|
: Cut string to desired length
|
|||
|
|
- [`d2w()`](https://agdamsbo.github.io/REDCapCAST/reference/d2w.md) :
|
|||
|
|
Convert single digits to words
|
|||
|
|
- [`doc2dd()`](https://agdamsbo.github.io/REDCapCAST/reference/doc2dd.md)
|
|||
|
|
: Doc table to data dictionary - EARLY, DOCS MISSING
|
|||
|
|
- [`ds2dd()`](https://agdamsbo.github.io/REDCapCAST/reference/ds2dd.md)
|
|||
|
|
: (DEPRECATED) Data set to data dictionary function
|
|||
|
|
- [`ds2dd_detailed()`](https://agdamsbo.github.io/REDCapCAST/reference/ds2dd_detailed.md)
|
|||
|
|
: Extract data from stata file for data dictionary
|
|||
|
|
- [`easy_redcap()`](https://agdamsbo.github.io/REDCapCAST/reference/easy_redcap.md)
|
|||
|
|
: Secure API key storage and data acquisition in one
|
|||
|
|
- [`export_redcap_instrument()`](https://agdamsbo.github.io/REDCapCAST/reference/export_redcap_instrument.md)
|
|||
|
|
: Creates zip-file with necessary content to manually add instrument
|
|||
|
|
to database
|
|||
|
|
- [`fct2num()`](https://agdamsbo.github.io/REDCapCAST/reference/fct2num.md)
|
|||
|
|
: Allows conversion of factor to numeric values preserving original
|
|||
|
|
levels
|
|||
|
|
- [`fct_drop()`](https://agdamsbo.github.io/REDCapCAST/reference/fct_drop.md)
|
|||
|
|
: Drop unused levels preserving label data
|
|||
|
|
- [`file_extension()`](https://agdamsbo.github.io/REDCapCAST/reference/file_extension.md)
|
|||
|
|
: DEPRECATED Helper to import files correctly
|
|||
|
|
- [`focused_metadata()`](https://agdamsbo.github.io/REDCapCAST/reference/focused_metadata.md)
|
|||
|
|
: focused_metadata
|
|||
|
|
- [`format_redcap_factor()`](https://agdamsbo.github.io/REDCapCAST/reference/format_redcap_factor.md)
|
|||
|
|
: Converts REDCap choices to factor levels and stores in labels
|
|||
|
|
attribute
|
|||
|
|
- [`format_subheader()`](https://agdamsbo.github.io/REDCapCAST/reference/format_subheader.md)
|
|||
|
|
: Sub-header formatting wrapper
|
|||
|
|
- [`get_api_key()`](https://agdamsbo.github.io/REDCapCAST/reference/get_api_key.md)
|
|||
|
|
: Retrieve project API key if stored, if not, set and retrieve
|
|||
|
|
- [`get_attr()`](https://agdamsbo.github.io/REDCapCAST/reference/get_attr.md)
|
|||
|
|
: Extract attribute. Returns NA if none
|
|||
|
|
- [`get_id_name()`](https://agdamsbo.github.io/REDCapCAST/reference/get_id_name.md)
|
|||
|
|
: Get the id name
|
|||
|
|
- [`guess_time_only()`](https://agdamsbo.github.io/REDCapCAST/reference/guess_time_only.md)
|
|||
|
|
: Guess time variables based on naming pattern
|
|||
|
|
- [`guess_time_only_filter()`](https://agdamsbo.github.io/REDCapCAST/reference/guess_time_only_filter.md)
|
|||
|
|
: Try at determining which are true time only variables
|
|||
|
|
- [`haven_all_levels()`](https://agdamsbo.github.io/REDCapCAST/reference/haven_all_levels.md)
|
|||
|
|
: Finish incomplete haven attributes substituting missings with values
|
|||
|
|
- [`hms2character()`](https://agdamsbo.github.io/REDCapCAST/reference/hms2character.md)
|
|||
|
|
: Change "hms" to "character" for REDCap upload.
|
|||
|
|
- [`html_tag_wrap()`](https://agdamsbo.github.io/REDCapCAST/reference/html_tag_wrap.md)
|
|||
|
|
: Simple html tag wrapping for REDCap text formatting
|
|||
|
|
- [`is.labelled()`](https://agdamsbo.github.io/REDCapCAST/reference/is.labelled.md)
|
|||
|
|
: Tests for multiple label classes
|
|||
|
|
- [`is_missing()`](https://agdamsbo.github.io/REDCapCAST/reference/is_missing.md)
|
|||
|
|
: Multi missing check
|
|||
|
|
- [`is_repeated_longitudinal()`](https://agdamsbo.github.io/REDCapCAST/reference/is_repeated_longitudinal.md)
|
|||
|
|
: Test if repeatable or longitudinal
|
|||
|
|
- [`mark_complete()`](https://agdamsbo.github.io/REDCapCAST/reference/mark_complete.md)
|
|||
|
|
: Completion marking based on completed upload
|
|||
|
|
- [`match_fields_to_form()`](https://agdamsbo.github.io/REDCapCAST/reference/match_fields_to_form.md)
|
|||
|
|
: Match fields to forms
|
|||
|
|
- [`mtcars_redcap`](https://agdamsbo.github.io/REDCapCAST/reference/mtcars_redcap.md)
|
|||
|
|
: mtcars dataset slightly modified to use for Shiny app upload
|
|||
|
|
demonstration
|
|||
|
|
- [`named_levels()`](https://agdamsbo.github.io/REDCapCAST/reference/named_levels.md)
|
|||
|
|
: Get named vector of factor levels and values
|
|||
|
|
- [`nav_bar_page()`](https://agdamsbo.github.io/REDCapCAST/reference/nav_bar_page.md)
|
|||
|
|
: Nav_bar defining function for shiny ui
|
|||
|
|
- [`numchar2fct()`](https://agdamsbo.github.io/REDCapCAST/reference/numchar2fct.md)
|
|||
|
|
: Applying var2fct across data set
|
|||
|
|
- [`parse_data()`](https://agdamsbo.github.io/REDCapCAST/reference/parse_data.md)
|
|||
|
|
: Helper to auto-parse un-formatted data with haven and readr
|
|||
|
|
- [`possibly_numeric()`](https://agdamsbo.github.io/REDCapCAST/reference/possibly_numeric.md)
|
|||
|
|
: Tests if vector can be interpreted as numeric without introducing
|
|||
|
|
NAs by coercion
|
|||
|
|
- [`possibly_roman()`](https://agdamsbo.github.io/REDCapCAST/reference/possibly_roman.md)
|
|||
|
|
: Test if vector can be interpreted as roman numerals
|
|||
|
|
- [`process_user_input()`](https://agdamsbo.github.io/REDCapCAST/reference/process_user_input.md)
|
|||
|
|
: User input processing
|
|||
|
|
- [`process_user_input(`*`<character>`*`)`](https://agdamsbo.github.io/REDCapCAST/reference/process_user_input.character.md)
|
|||
|
|
: User input processing character
|
|||
|
|
- [`process_user_input(`*`<data.frame>`*`)`](https://agdamsbo.github.io/REDCapCAST/reference/process_user_input.data.frame.md)
|
|||
|
|
: User input processing data.frame
|
|||
|
|
- [`process_user_input(`*`<default>`*`)`](https://agdamsbo.github.io/REDCapCAST/reference/process_user_input.default.md)
|
|||
|
|
: User input processing default
|
|||
|
|
- [`process_user_input(`*`<response>`*`)`](https://agdamsbo.github.io/REDCapCAST/reference/process_user_input.response.md)
|
|||
|
|
: User input processing response
|
|||
|
|
- [`read_input()`](https://agdamsbo.github.io/REDCapCAST/reference/read_input.md)
|
|||
|
|
: Flexible file import based on extension
|
|||
|
|
- [`read_redcap_instrument()`](https://agdamsbo.github.io/REDCapCAST/reference/read_redcap_instrument.md)
|
|||
|
|
: Convenience function to download complete instrument, using token
|
|||
|
|
storage in keyring.
|
|||
|
|
- [`read_redcap_tables()`](https://agdamsbo.github.io/REDCapCAST/reference/read_redcap_tables.md)
|
|||
|
|
: Download REDCap data
|
|||
|
|
- [`redcap_wider()`](https://agdamsbo.github.io/REDCapCAST/reference/redcap_wider.md)
|
|||
|
|
: Transforms list of REDCap data.frames to a single wide data.frame
|
|||
|
|
- [`redcapcast_data`](https://agdamsbo.github.io/REDCapCAST/reference/redcapcast_data.md)
|
|||
|
|
: Data set for demonstration
|
|||
|
|
- [`redcapcast_meta`](https://agdamsbo.github.io/REDCapCAST/reference/redcapcast_meta.md)
|
|||
|
|
: REDCap metadata from data base
|
|||
|
|
- [`replace_curly_quote()`](https://agdamsbo.github.io/REDCapCAST/reference/replace_curly_quote.md)
|
|||
|
|
: Replace curly apostrophes and quotes from word
|
|||
|
|
- [`sanitize_split()`](https://agdamsbo.github.io/REDCapCAST/reference/sanitize_split.md)
|
|||
|
|
: Sanitize list of data frames
|
|||
|
|
- [`set_attr()`](https://agdamsbo.github.io/REDCapCAST/reference/set_attr.md)
|
|||
|
|
: Set attributes for named attribute. Appends if attr is NULL
|
|||
|
|
- [`shiny_cast()`](https://agdamsbo.github.io/REDCapCAST/reference/shiny_cast.md)
|
|||
|
|
: Launch the included Shiny-app for database casting and upload
|
|||
|
|
- [`split_non_repeating_forms()`](https://agdamsbo.github.io/REDCapCAST/reference/split_non_repeating_forms.md)
|
|||
|
|
: Split a data frame into separate tables for each form
|
|||
|
|
- [`strsplitx()`](https://agdamsbo.github.io/REDCapCAST/reference/strsplitx.md)
|
|||
|
|
: Extended string splitting
|
|||
|
|
- [`suffix2label()`](https://agdamsbo.github.io/REDCapCAST/reference/suffix2label.md)
|
|||
|
|
: Transfer variable name suffix to label in widened data
|
|||
|
|
- [`time_only_correction()`](https://agdamsbo.github.io/REDCapCAST/reference/time_only_correction.md)
|
|||
|
|
: Correction based on time_only_filter function
|
|||
|
|
- [`var2fct()`](https://agdamsbo.github.io/REDCapCAST/reference/var2fct.md)
|
|||
|
|
: Convert vector to factor based on threshold of number of unique
|
|||
|
|
levels
|
|||
|
|
- [`vec2choice()`](https://agdamsbo.github.io/REDCapCAST/reference/vec2choice.md)
|
|||
|
|
: Named vector to REDCap choices (\`wrapping compact_vec()\`)
|
|||
|
|
|
|||
|
|
# Articles
|
|||
|
|
|
|||
|
|
### All vignettes
|
|||
|
|
|
|||
|
|
- [Database-creation](https://agdamsbo.github.io/REDCapCAST/articles/Database-creation.md):
|
|||
|
|
- [REDCapCAST](https://agdamsbo.github.io/REDCapCAST/articles/REDCapCAST.md):
|
|||
|
|
- [Shiny-app](https://agdamsbo.github.io/REDCapCAST/articles/Shiny-app.md):
|