Learn R Programming

⚠️There's a newer version (2.9.1) of this package.Take me there.

redcapAPI

Quick Start Guide

There are 2 basic functions that are key to understanding the major changes with this version:

  • unlockREDCap
  • exportBulkRecords

Here's a typical call for these two:

library(redcapAPI)

options(keyring_backend=keyring::backend_file) # Put in .Rprofile

unlockREDCap(c(rcon    = '<MY PROJECT NAME>'),
             keyring     = 'API_KEYs',
             envir       = globalenv(),
             url         = 'https://<REDCAP_URL>/api/')
exportBulkRecords(list(db = rcon),
  forms = list(db = unique(rcon$metadata()$form_name)),
  envir = globalenv())

The <MY PROJECT NAME> is a reference for whatever you wish to call this REDCap project. The rcon is the variable you wish to assign it too. The keyring is a name for this key ring. If one uses 'API_KEYs' for all your projects, you'll have one big keyring for all your API_KEYs locally encrypted. The url is the standard url for the api. The passwordFUN specified is an override if one is using RStudio. It's not required, but on a Mac this is the only option that works well. The envir call is where to write the connection object; if not specified the call will return a list.

The next call to exportBulkRecords, says to export by form and leave out records not filled out and columns not part of a form. The first argument is specifying a db reference to the connection opened and naming it the same thing. The second call is saying for this connection export back the all the forms present in that db. The envir has it writing it back to the global environment as variables. Any parameter not recognized is passed to the exportRecordsTyped call.

These two calls will handle most analysis requests. To truly understand all these changes see: vignette("redcapAPI-best-practices")

2.7.0+

2.7.0 includes exportRecordsTyped which is a major move forward for the package. It replaces exportRecords with a far more stable and dependable call. It includes retries with exponential backoff through the connection object. It has inversion of control over casting, and has a useful validation report attached when things fail. It is worth the time to convert calls to exportRecords to exportRecordsTyped and begin using this new routine. It is planned that in the next year exportRecords will be removed from the package.

Back Matter

NOTE: Ownership transfer of this package to VUMC Biostatistics is complete.

The research community owes a big thanks to Benjamin Nutter for his years of service keeping this package current.

The package redcapAPI is an R interface to REDCap (http://www.project-redcap.org/), originally created by Jeffrey Horner.

Please read the documentation on your institutions REDCap installation.

Issues may be reported at Issues

This package was developed under REDCap Version 13.4.3. Institutions can be a little behind on updating REDCap and so some features of the API may not always work.

Coding Style Guideline Note

  • Exported function names: dromedaryCase
  • Internal function names: .dromedaryCase
  • Constant data exported: UPPERCASE
  • Function parameters: snake_case
  • Function variables: snake_case
    • (exception) data.frame variable: CamelCase

Copy Link

Version

Install

install.packages('redcapAPI')

Monthly Downloads

1,012

Version

2.7.4

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

July 17th, 2023

Functions in redcapAPI (2.7.4)

deprecated_redcapProjectInfo

Deprecated Functions
exportBulkRecords

A helper function to export multiple records and forms using a single call.
exportMappings

Exports the Event-Form Mappings for a Project
exportMetaData

Export Meta Data from a REDCap Database
exportArms

Export the Arms for a Project
exportFileRepositoryListing

Export a Listing of Folders and Files in the File Repository
deleteRecords

Delete Records From a Project
exportFileRepository

Export All Files From a Directory in the File Repository
deleteFromFileRepository

Delete a Single File from the File Repository
dropRepeatingNA

Drop Row Where Repeat Instrument Is NA
exportInstruments

Exports the REDCap Instruments
exportReports

Export Reports from a REDCap Database
exportVersion

Exports the REDCap Version Number
exportLogging

Export Logging Records
fieldCastingFunctions

Functions for Casting Fields After Export (Post Processing)
checkbox_suffixes

Checkbox Suffixes
exportPdf

Export PDF file of Data Collection Instruments (either as blank or with data)
exportBundle

Perform a bundle of API calls.
exportDags

Export Data Access Groups
fileRepositoryPath

Reconstruct the file repository path
fieldValidationAndCasting

Helper functions for exportRecordsTyped Validation and Casting
exportEvents

Export the Events for a Project
exportFiles

Exports a File attached to a Record
exportFieldNames

Export the Export Field Names for a Project
exportProjectInformation

Exports the Project Information
exportNextRecordName

Generate Next Record Name from a REDCap Database
exportRecords

Export Records from a REDCap Database
exportReportsTyped

Export a Report from a REDCap Project
getProjectIdFields

Return a vector of the Project ID Fields
filterEmptyRow

Remove Rows Containing Only Missing Values
importToFileRepository

Import a Single File to the File Repository
exportRecordsTyped

A replacement for exportRecords with full inversion of control over type casting.
exportRepeatingInstrumentsEvents

Export Repeating Instruments and Events Settings
fieldChoiceMapping

Splits a Field Choice Mapping Into a Two Column Matrix
stringCleanup

Remove Undesired Characters From Strings
fieldToVar

Convert a REDCap Data Field to an R Vector
massert

Conduct Multiple Assertions
importProjectInformation

Import Project Information
exportUsers

Export the Users for a Project
exportSurveyParticipants

Exports details of participants for a given survey
importArms

Import Study Arm Names
makeApiCall

Make REDCap API Calls
missingSummary

Report of Missing Values
importRepeatingInstrumentsEvents

Import Repeating Instruments and Events Settings
splitForms

Split a Data Frame into its Forms
purgeRestoreProject

Purge and Restore Project Data
recodeCheck

Change labelling of checkbox variables
reconstituteFileFromExport

Save a File to a Local Directory from a Response
importRecords

Import Records to a REDCap Database
importMappings

Import Instrument Event Mapping
redcapFactorFlip

Convert REDCap factors between labelled and coded
redcap_error

Handle Errors from the REDCap API
importMetaData

Import Meta Data (Data Dictionary) to a Project
importEvents

Import Events to REDCap
prepUserImportData

Prepare User Data for Import
format.invalid

Helper functions for formatting validation failure report
parseBranchingLogic

Parse Branching Logic
vectorToApiBodyList

Convert R Vector To List for the API Call Body
redcapAPI

Access data, meta data, and files from REDCap using the API
validateImport

Validate Data Frames for Import
widerRepeated

Transform Data Into Wide Format
writeDataForImport

Prepare a Data Frame for Import Through the API
redcapConnection

Connect to a REDCap Database
redcapDataStructures

REDCap Data Structures
importFiles

Imports a File to REDCap to Attach to a Record
exportFromFileRepository

Export a File from the File Repository
importFileRepository

Import a Folder and its Contents to the File Repository
syncUnderscoreCodings

Synchronize coding of checkbox variables between meta data and records field names.
unlockREDCap

Open REDCap connections using cryptolocker for storage of API_KEYs.
Extraction

Extraction and Assignment for redcapFactors
allocationTable

Generate Allocation Tables for the Randomization Module
stripHTMLandUnicode

Helper functions for exportRecordsTyped attributes
createFileRepositoryFolder

Create a Folder in the File Repository
deleteEvents

Delete Events from a Project
deleteFiles

Delete a File attached to a Record
deleteArms

Delete Arms From a Project
cleanseMetaData

Clean Meta Data of UTF Characters
deleteFileRepository

Delete All Files from the File Repository