REDCapDM - Data reading and processing"

rm(list = ls())
library(REDCapDM) 
library(kableExtra)
library(knitr)
library(dplyr)
library(magrittr)
library(purrr)


This vignette provides a summary of the straightforward and common use of REDCapDM to interact with REDCap data.


Read data

To import data from REDCap, you can use the redcap_data() function, which provides two primary methods: importing data from local files or establishing an API connection.

Local files

Before starting, ensure you have the required R and CSV files exported from REDCap, including the instrument-event mappings file. All these files should be in the same directory for the package to work correctly.

Use the data_path and dic_path arguments to indicate the paths to your R data file and REDCap project's dictionary file, respectively. If your REDCap project is longitudinal, you'll additionally need to supply the event-form mapping file using the event_path argument.

dataset <- redcap_data(data_path = "C:/Users/username/example.r",
                       dic_path = "C:/Users/username/example_dictionary.csv",
                       event_path = "C:/Users/username/events.csv")

API connection

If you opt for an API connection, you can provide the uri (uniform resource identifier) and token (user-specific password) for your REDCap project. This method will automatically retrieve the event-form mapping if your project is longitudinal.

Use both arguments to set up the API connection and import the data:

dataset_api <- redcap_data(uri = "https://redcap.idibell.cat/api/",
                           token = "55E5C3D1E83213ADA2182A4BFDEA")

Output

The redcap_data() function returns a list with three elements:



Process data

Having successfully imported our data into R, you can now use the rd_transform() function to start processing the data.

This function performs several transformations:

Standard

The only essential elements that must be supplied are the dataset to be transformed and the corresponding dictionary. In the case of a longitudinal project, it is advisable to also specify the event form dataset to take full advantage of this function. These elements can be directly specified using the output of the redcap_data() function or separately using distinct arguments:

#Option A: list object 
covican_transformed <- rd_transform(covican)

#Option B: separately with different arguments
covican_transformed <- rd_transform(data = covican$data, 
                                    dic = covican$dictionary, 
                                    event_form = covican$event_form)

This function returns a list containing the transformed dataset, dictionary, event_form and the results of each transformation. To retrieve the results of the transformation, use the following code block:

#Print the results of the transformation
covican_transformed$results

By event

If the REDCap project is longitudinal, you can further adjust the structure of the transformed dataset. For example, it can be split by event:

dataset <- rd_transform(covican,
                        final_format = "by_event")

Where the transformed dataset is a tibble object, containing data frames for each event in the REDCap project.

dataset$data

By form

Or, alternatively, it can be split by form:

dataset <- rd_transform(covican,
                        final_format = "by_form")

Where the tibble object is composed by data frames corresponding to each form in the REDCap project.

dataset$data



For more information, consult the complete vignette available at: https://bruigtp.github.io/REDCapDM/articles/REDCapDM.html





Try the REDCapDM package in your browser

Any scripts or data that you put into this service are public.

REDCapDM documentation built on June 22, 2024, 12:02 p.m.