exportBulkRecords: A helper function to export multiple records and forms using...

View source: R/exportRecordsTyped.R

exportBulkRecordsR Documentation

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

Description

Exports records from multiple REDCap Databases using multiple calls to exportRecordsTyped()

Usage

exportBulkRecords(
  rcon,
  forms = NULL,
  envir = NULL,
  sep = "_",
  post = NULL,
  ...
)

Arguments

rcon

A redcapConnection object.

forms

A named list that is a subset of rcon's names. A specified rcon will provide a list of forms for repeated calls to exportRecordsType. If a connection reference is missing it will default to all forms. To override this default specify a connection's forms with NA to just get all data.

envir

A environment to write the resulting Records in as variables given by their name in rcon or if from a form their rcon named pasted to their form name joined by sep. If not specified the function will return a named list with the results. Will accept a number of the environment.

sep

A character string to use when joining the rcon name to the form name for storing variables.

post

A function that will run on all returned sets of Records.

...

Any additional variables to pass to exportRecordsTyped().

Value

Will return a named list of the resulting records if envir is NULL. Otherwise will assign them to the specified envir.

Examples

## Not run: 
unlockREDCap(c(test_conn    = 'TestRedcapAPI',
               sandbox_conn = 'SandboxAPI'),
             keyring      = 'MyKeyring',
             envir        = globalenv(),
             url          = 'https://<REDCAP_URL>/api/') 

# After user interaction to unlock the local encrypted keyring
# the global environment will contain the REDCap connections
# `test_conn` and `sandbox_conn`
# 
# Next the user wants to bulk specify importing all the forms
# of interest and post process

exportBulkRecords(
 rcon  = list(test = test_conn,
              sand = sandbox_conn),
 forms = list(test = c('form1', 'form2'),
 envir = globalenv(),
 post  = function(Records, rcon)
         {
           Records              |>
           mChoiceCast(rcon)    |>
           guessDat(rcon)       |>
           widerRepeating(rcon)
         }
 )
 
# The environment now contains the data.frames: `test.form1`, `test.form2`, `sand`.
# Each of these were retrieved, possibly using the forms argument and all were
# post processed in the same manner as specified by `post`.

## End(Not run)

redcapAPI documentation built on Sept. 13, 2023, 1:07 a.m.