mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 13:17:30 +02:00
major update with new functions and renv is out! see NEWS section
This commit is contained in:
parent
b35142f0cc
commit
4a56f4ec45
16 changed files with 158 additions and 93 deletions
|
|
@ -18,33 +18,59 @@ knitr::opts_chunk$set(
|
|||
library(REDCapCAST)
|
||||
```
|
||||
|
||||
# Easy data set to data base workflow
|
||||
# Two different ways to create a data base
|
||||
|
||||
THe first iteration of a dataset to data dictionary function is the `ds2dd()`, which creates a very basic data dictionary with all variables stored as text. This is sufficient for just storing old datasets/spreadsheets securely in REDCap.
|
||||
`REDCapCAST` provides two approaches to creating a data dictionary aimed at helping out in two different cases:
|
||||
|
||||
```{r eval=FALSE}
|
||||
mtcars |>
|
||||
1. Easily create a REDCap data base from an existing data set.
|
||||
|
||||
2. Create a table in Word describing a variables in a data base and use this to create a data base.
|
||||
|
||||
In the following I will try to come with a few suggestions on how to use these approaches.
|
||||
|
||||
## Easy data set to data base workflow
|
||||
|
||||
The first iteration of a dataset to data dictionary function is the `ds2dd()`, which creates a very basic data dictionary with all variables stored as text. This is sufficient for just storing old datasets/spreadsheets securely in REDCap.
|
||||
|
||||
```{r eval=TRUE}
|
||||
d1 <- mtcars |>
|
||||
dplyr::mutate(record_id = seq_len(dplyr::n())) |>
|
||||
ds2dd() |>
|
||||
str()
|
||||
ds2dd()
|
||||
|
||||
d1 |>
|
||||
gt::gt()
|
||||
```
|
||||
|
||||
The more advanced `ds2dd_detailed()` is a natural development. It will try to apply the most common data classes for data validation and will assume that the first column is the id number. It outputs a list with the dataset with modified variable names to comply with REDCap naming conventions and a data dictionary.
|
||||
|
||||
The dataset should be correctly formatted for the data dictionary to preserve as much information as possible.
|
||||
|
||||
```{r eval=FALSE}
|
||||
dd_ls <- mtcars |>
|
||||
dplyr::mutate(record_id = seq_len(dplyr::n())) |>
|
||||
```{r eval=TRUE}
|
||||
d2 <- REDCapCAST::redcapcast_data |>
|
||||
dplyr::mutate(record_id = seq_len(dplyr::n()),
|
||||
region=factor(region)) |>
|
||||
dplyr::select(record_id, dplyr::everything()) |>
|
||||
ds2dd_detailed()
|
||||
dd_ls |>
|
||||
str()
|
||||
(\(.x){
|
||||
.x[!grepl("_complete$",names(.x))]
|
||||
})() |>
|
||||
(\(.x){
|
||||
.x[!grepl("^redcap",names(.x))]
|
||||
})() |>
|
||||
ds2dd_detailed() |>
|
||||
purrr::pluck("meta")
|
||||
|
||||
d2 |>
|
||||
gt::gt()
|
||||
```
|
||||
|
||||
Additional specifications to the DataDictionary can be made manually, or it can be uploaded and modified manually in the graphical user interface on the web page.
|
||||
Additional specifications to the DataDictionary can be made manually, or it can be uploaded and modified manually in the graphical user interface on the REDCap server.
|
||||
|
||||
## Step 3 - Meta data upload
|
||||
## Data base from table
|
||||
|
||||
|
||||
|
||||
|
||||
## Meta data and data upload
|
||||
|
||||
Now the DataDictionary can be exported as a spreadsheet and uploaded or it can be uploaded using the `REDCapR` package (only projects with "Development" status).
|
||||
|
||||
|
|
|
|||
|
|
@ -14,10 +14,6 @@ knitr::opts_chunk$set(
|
|||
)
|
||||
```
|
||||
|
||||
```{r setup}
|
||||
library(REDCapCAST)
|
||||
```
|
||||
|
||||
To make the easiest possible transition from spreadsheet/dataset to REDCap, I have created a small Shiny app, which adds a graphical interface to the casting of a data dictionary and data upload. Install the package and run the app as follows:
|
||||
|
||||
```{r eval=FALSE}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue