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 (https://www.projectredcap.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.8.2. 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.8.0

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

September 12th, 2023

Functions in redcapAPI (2.8.0)

deleteRecords

Delete Records from a Project
exportInstruments

Export Instruments Defined in a Project
exportLogging

Export Logging Records
exportBulkRecords

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

Export PDF file of Data Collection Instruments
eventsMethods

Export, Import, and Delete Event Settings
exportFieldNames

Export the Complete Field Names for a REDCap Project
deprecated_redcapProjectInfo

Deprecated Functions
exportFileRepositoryListing

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

Drop Row Where Repeat Instrument Is NA
fieldValidationAndCasting

Helper functions for exportRecordsTyped Validation and Casting
filterEmptyRow

Remove Rows Containing Only Missing Values
exportVersion

Export the REDCap Version Number
fieldCastingFunctions

Functions for Casting Fields After Export (Post Processing)
fileMethods

Export, Import, or Delete Files to a Field in a REDCap Project
fromFileRepositoryMethods

Export, Import, and Delete Individual Files from the File Repository
exportBundle

Perform a bundle of API calls.
fieldChoiceMapping

Split a Field Choice Mapping Into a Two Column Matrix
fieldToVar

Convert a REDCap Data Field to an R Vector
fileRepositoryPath

Reconstruct the file repository path
fileRepositoryMethods

Export, Import, or Delete Multiple Files from the File Repository
invalidSummary

Helper functions for formatting validation failure report
parseBranchingLogic

Parse Branching Logic
isZeroCodedCheckField

Identify Check Fields with a Zero Coded Option
missingSummary

Report of Missing Values
getProjectIdFields

Return a vector of the Project ID Fields
metaDataMethods

Export and Import the Project Meta Data (Data Dictionary)
massert

Conduct Multiple Assertions
importRecords

Import Records to a Project
makeApiCall

Make REDCap API Calls
mappingMethods

Export and Import Instrument-Event Mappings
redcapAPI

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

Save a File to a Local Directory from a Response
recordsManagementMethods

Export Next Record Name or Rename a Record
purgeRestoreProject

Purge and Restore Project Data
recodeCheck

Change labeling of checkbox variables
redcapConnection

Connect to a REDCap Database
prepUserImportData

Prepare User Data for Import
projectInformationMethods

Export and Import Project Settings
surveyMethods

Export Survey Participant Information
syncUnderscoreCodings

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

Switch Data Access Group Assignment for the Current User
stringCleanup

Remove Undesired Characters From Strings
reviewInvalidRecords

Review Invalid Records Following Field Validation
splitForms

Split a Data Frame into its Forms
redcapError

Handle Errors from the REDCap API
redcapDataStructures

REDCap Data Structures
repeatingInstrumentMethods

Export or Import Repeating Instrument and Events Settings
redcapFactorFlip

Convert REDCap factors between labeled and coded
recordsTypedMethods

Export Records or Reports From a Project
recordsMethods

Export Records and Reports
validateImport

Validate Data Frames for Import
vectorToApiBodyList

Convert R Vector To List for the API Call Body
writeDataForImport

Prepare a Data Frame for Import Through the API
widerRepeated

Transform Data Into Wide Format
unlockREDCap

Open REDCap connections using cryptolocker for storage of API_KEYs.
userMethods

Export, Import, or Delete Users and User Permissisons
userRoleAssignmentMethods

Export or Import User-Role Assignments
userRoleMethods

Export, Import, or Delete User Roles in a Project
allocationTable

Generate Allocation Tables for the Randomization Module
dagAssignmentMethods

Export and Import Users Assigned to Data Access Groups
cleanseMetaData

Clean Meta Data of UTF Characters
checkbox_suffixes

Checkbox Suffixes
armsMethods

Export, Import, and Delete Arms from a Project
Extraction

Extraction and Assignment for redcapFactors
dagMethods

Export, Import, Delete Data Access Groups from a Project
createFileRepositoryFolder

Create a Folder in the File Repository
stripHTMLandUnicode

Helper Functions for exportRecordsType Attributes