major update with new functions and renv is out! see NEWS section

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-06-07 10:35:16 +02:00
commit 4a56f4ec45
16 changed files with 158 additions and 93 deletions

View file

@ -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).

View file

@ -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}