rc_import: Import Records to a REDCap Database

View source: R/rc_import.R

rc_importR Documentation

Import Records to a REDCap Database

Description

Imports records from a data.frame to a REDCap Database

Usage

rc_import(
  record_data,
  url = getOption("redcap_bundle")$redcap_url,
  token = getOption("redcap_token"),
  data_dict = getOption("redcap_bundle")$data_dict,
  overwriteBehavior = "normal",
  returnContent = "count",
  returnData = FALSE,
  logfile = "",
  batch_size = -1
)

Arguments

record_data

A data.frame to be imported to the REDCap project.

url

A url address to connect to the REDCap API

token

Path to a text file containing your REDCap API token

data_dict

Dataframe. A REDCap project data dictionary. By default, $data_dict is expected in the REDCap bundle option, as created by rc_bundle.

overwriteBehavior

Character string. 'normal' prevents existing data in REDCap from being altered. Note that when set to 'overwrite', blank values (NAs) will replace existing data.

returnContent

Character string. 'count' returns the number of records imported; 'ids' returns a list of record ids imported; 'nothing' returns no message.

returnData

Logical. Prevents the REDCap import and instead returns the data frame that would have been given for import. This is sometimes helpful if the API import fails without providing an informative message. The data frame can be written to a csv and uploaded using the interactive tools to troubleshoot the problem. Please shoot me an e-mail if you find errors I haven't accounted for.

logfile

An optional filepath (preferably .txt) in which to print the log of errors and warnings about the data. If "", the log is printed to the console.

batch_size

Specifies size of batches. A negative value indicates no batching.

Details

A record of imports through the API is recorded in the Logging section of the project.

rc_import prevents the most common import errors by testing the data before attempting the import. Namely

  1. Check that all variables in record_data exist in the REDCap data data_dictionary.

  2. Check that the study id variable exists

  3. Force the study id variable to the first position in the data frame (with a warning)

  4. Remove calculated fields (with a warning)

  5. Verify that REDCap date fields are represented in the data frame as either character, POSIXct, or Date class objects.

  6. Determine if values are within their specified validation limits.

See the documentation for validateImport for detailed explanations of the validation.

Author(s)

Benjamin Nutter
with thanks to Josh O'Brien and etb (see references)

Marcus Lehr

References

http://stackoverflow.com/questions/12393004/parsing-back-to-messy-api-strcuture/12435389#12435389
https://github.com/etb/my-R-code/blob/master/R-pull-and-push-from-and-to-REDCap.R
See also the REDCap API documentation Please refer to your institution's API documentation.

Additional details on API parameters are found on the package wiki at https://github.com/nutterb/redcapAPI/wiki/REDCap-API-Parameters

See Also

validateImport


chillywings/rctools documentation built on Aug. 9, 2024, 11:52 p.m.