1  Data access

2 Data access

This section is intended as a “REDCap data manipulation 101” for pre-graduate students in the group and as an intro to getting RStudio set up for working with REDCap data in general.

Working with data in general, a rule of thumb is to store as little sensitive data as possible directly on your computer. The old way, would be to get a spreadsheet and have that on your computer. We don’t consider that safe or good practice any more. A better way is to store data on a secure server and only access the necessary data in the required timespan and then have the data deleted again. Any accumulated analysis results as figures and tables can of course be saved locally if they are correctly created.

We use REDCap to store research data. There are a few R-packages, that lets us work with data from REDCap directly in R, to achieve the above goal of secure data handling. In this book, the interface between R and REDCap is based on the REDCapR-package(Beasley 2022), but with extended functionality to handle the castlelated data of REDCap datasets when using longitudanl functionality and repeating events, through the REDCapCAST-package.(Damsbo and Egeler 2023)

The REDCapR-package contains a lot of great functions, that is use-full in advanced use cases. In the following things have been simplified a little for the new user.

A more thorough discussion on REDCap data can be found later as well as a chapter on tips to building a REDCap database.

2.1 Getting access

Before you are able to get any data out of REDCap, make sure that you are able to get in to REDCap, meaning you’ve had a user created by the project administrator (your supervisor will know). To access the REDCap web interface, a username, password an done-time-token is used. To access through R, a so-called API-key is used, which is an alpha-numeric key used to verify yourself to the REDCap server, when requesting data export.


The API key equals user name and password, and circumvents the two-factor verification process. Naturally, the API key should be kept in a safe way.


Instead of storing the API-key in your R-script or in a text-file on your computer, the keyring-package can be used to store your API key in your operating systems secure keychain.(Csárdi 2023)

Below will follow an easy-to-use implementation with secure API key storage and data retrieval.


To make everything as easy as possible, I suggest the following code example to retrieve your data set. If you run it for the first time, you will be prompted to insert your API-key.

  project.name = "YOUR PROJECT NAME",
  uri = "https://redcap.au.dk/api/",
  fields = c(
    # record_id benyttes alene som index
    # Alder og køn
    "age", "kon")