knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
To make the easiest possible transition from spreadsheet/dataset to REDCap, I have created a small app, which adds a graphical interface to the casting of a data dictionary and data upload. Install the package and launch the app as follows:
REDCapCAST::shiny_cast()
The app primarily wraps one function: ds2dd_detailed()
.
library(REDCapCAST) ds <- REDCap_split( records = redcapcast_data, metadata = redcapcast_meta, forms = "all" ) |> sanitize_split() |> redcap_wider() str(ds)
ds|> ds2dd_detailed(metadata = names(REDCapCAST::redcapcast_meta))|> purrr::pluck("data") |> str()
ds|> ds2dd_detailed(metadata = names(REDCapCAST::redcapcast_meta))|> purrr::pluck("meta") |> head(10)
Different data formats are accepted, which all mostly implements the readr::col_guess()
functionality to parse column classes.
To ensure uniformity in data import this parsing has been implemented on its own to use with ds2dd_detailed()
or any other data set for that matter:
ds_parsed <- redcapcast_data |> dplyr::mutate(dplyr::across(dplyr::everything(),as.character)) |> parse_data() str(ds_parsed)
It will ignore specified columns, which is neat for numeric-looking strings like cpr-with a leading 0:
redcapcast_data |> dplyr::mutate(dplyr::across(dplyr::everything(),as.character)) |> parse_data(ignore.vars = c("record_id","cpr")) |> str()
Column classes can be passed to parse_data()
.
Making a few crude assumption for factorising data, numchar2fct()
factorises numerical and character vectors based on a set threshold for unique values:
mtcars |> str() mtcars |> numchar2fct(numeric.threshold = 6) |> str()
ds_parsed|> numchar2fct(numeric.threshold = 2) |> str()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.