Learn R Programming

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

redcapAPI

Quick Start Guide for 2.7.1

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:

unlockREDCap(c(rcon    = '<MY PROJECT NAME>'),
             keyring     = 'API_KEYs',
             envir       = globalenv(),
             url         = 'https://<REDCAP_URL>/api/',
             passwordFUN = rstudioapi::askForPassword)
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 dependeable 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,110

Version

2.7.1

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Shawn Garbett

Last Published

June 12th, 2023

Functions in redcapAPI (2.7.1)

stripHTMLandUnicode

Helper functions for exportRecordsTyped attributes
deleteArms

Delete Arms From a Project
deleteFromFileRepository

Delete a Single File from the File Repository
exportArms

Export the Arms for a Project
dropRepeatingNA

Drop Row Where Repeat Instrument Is NA
exportFieldNames

Export the Export Field Names for a Project
exportEvents

Export the Events for a Project
deleteRecords

Delete Records From a Project
deleteFiles

Delete a File attached to a Record
exportBundle

Perform a bundle of API calls.
exportBulkRecords

A helper function to export multiple recordss and forms using a single call.
deprecated_redcapProjectInfo

Deprecated Functions
exportMappings

Exports the Event-Form Mappings for a Project
exportFiles

Exports a File attached to a Record
exportMetaData

Export Meta Data from a REDCap Database
exportPdf

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

Export a File from the File Repository
exportNextRecordName

Generate Next Record Name from a REDCap Database
exportInstruments

Exports the REDCap Instruments
exportLogging

Export Logging Records
exportFileRepository

Export All Files From a Directory in the File Repository
exportFileRepositoryListing

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

Exports the Project Information
exportRecordsTyped

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

Functions for Casting Fields After Export (Post Processing)
exportRepeatingInstrumentsEvents

Export Repeating Instruments and Events Settings
exportVersion

Exports the REDCap Version Number
exportReports

Export Reports from a REDCap Database
exportReportsTyped

Export a Report from a REDCap Project
exportUsers

Export the Users for a Project
exportSurveyParticipants

Exports details of participants for a given survey
getProjectIdFields

Return a vector of the Project ID Fields
filterEmptyRow

Remove Rows Containing Only Missing Values
exportRecords

Export Records from a REDCap Database
importEvents

Import Events to REDCap
importArms

Import Study Arm Names
fileRepositoryPath

Reconstruct the file repository path
fieldValidationAndCasting

Helper functions for exportRecordsTyped Validation and Casting
fieldToVar

Convert a REDCap Data Field to an R Vector
fieldChoiceMapping

Splits a Field Choice Mapping Into a Two Column Matrix
importFiles

Imports a File to REDCap to Attach to a Record
importFileRepository

Import a Folder and its Contents to the File Repository
importMappings

Import Instrument Event Mapping
massert

Conduct Multiple Assertions
importMetaData

Import Meta Data (Data Dictionary) to a Project
importRepeatingInstrumentsEvents

Import Repeating Instruments and Events Settings
importProjectInformation

Import Project Information
importRecords

Import Records to a REDCap Database
importToFileRepository

Import a Single File to the File Repository
missingSummary

Report of Missing Values
makeApiCall

Make REDCap API Calls
format.invalid

Helper functions for formatting validation failure report
recodeCheck

Change labelling of checkbox variables
splitForms

Split a Data Frame into its Forms
parseBranchingLogic

Parse Branching Logic
redcapFactorFlip

Convert REDCap factors between labelled and coded
redcapConnection

Connect to a REDCap Database
purgeRestoreProject

Purge and Restore Project Data
redcapDataStructures

REDCap Data Structures
reconstituteFileFromExport

Save a File to a Local Directory from a Response
redcap_error

Handle Errors from the REDCap API
redcapAPI

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

Create a set of connections to redcap in the current (or specified environment) from API_KEYs stored in a crypto locker. On the first execution it will ask to set the password for this locker. Next it will ask for the API_KEYs specified. It will request the user enter each key using getPass and store it in memory. If an API_KEY doesn't work, it will automatically delete it from the crypto locker and ask again on next execution.
vectorToApiBodyList

Convert R Vector To List for the API Call Body
widerRepeated

Transform Data Into Wide Format
stringCleanup

Remove Undesired Characters From Strings
validateImport

Validate Data Frames for Import
writeDataForImport

Prepare a Data Frame for Import Through the API
syncUnderscoreCodings

Sychronize coding of checkbox variables between meta data and records field names.
cleanseMetaData

Clean Meta Data of UTF Characters
deleteFileRepository

Delete All Files from the File Repository
createFileRepositoryFolder

Create a Folder in the File Repository
constants

Constants for Use in the redcapAPI Package
deleteEvents

Delete Events from a Project
allocationTable

Allocation Tables for the Randomization Module
Extraction

Extraction and Assignment for redcapFactors
checkbox_suffixes

Checkbox Suffixes