Skip to contents

This function allows users to read datasets from a REDCap project into R for analysis, either by exporting the data or via an API connection.

The REDCap API serves as an interface for communication with REDCap and the server without requiring interaction through the REDCap interface.

[Important] To read exported data from REDCap, please follow these steps:

- Use REDCap's 'Export Data' function.

- Select the 'R Statistical Software' format.

- REDCap will then generate two files:

- A CSV file containing all observations of the REDCap project.

- An R file with the necessary code to complete each variable's information and import them.

- Ensure these files, along with the dictionary and event-mapping, are in the same directory.

Usage

redcap_data(
  data_path = NA,
  dic_path = NA,
  event_path = NA,
  uri = NA,
  token = NA,
  filter_field = NULL,
  survey_fields = FALSE
)

Arguments

data_path

Character string specifying the path of the R file from which the dataset will be read.

dic_path

Character string with the path of the dictionary.

event_path

Character string specifying the path of the file containing the correspondence between each event and each form (downloadable via the `Designate Instruments for My Events` tab within the `Project Setup` section of REDCap).

uri

The URI (Uniform Resource Identification) of the REDCap project.

token

Character vector containing the generated token.

filter_field

Character vector specifying the fields of the REDCap project desired to be imported into R (via API connection only).

survey_fields

Logical indicating whether the function should download all the survey-related fields of the REDCap project (via API connection only).

Value

A list containing the dataset and the dictionary of the REDCap project. If `event_path` is specified, it will also contain a third element with the correspondence of the events and forms of the project.

Note

For further use of the package, it's recommended to use the `dic_path` argument to read the dictionary, as all other functions require it for proper functioning.

Examples

if (FALSE) { # \dontrun{
# Exported files from REDCap

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

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

} # }