Learn R Programming

REDCapR (version 0.9.3)

redcap_write_oneshot: Write/Import records to a REDCap project.

Description

This function uses REDCap's API to select and return data.

Usage

redcap_write_oneshot(ds, redcap_uri, token, verbose = TRUE, config_options = NULL)

Arguments

ds
The data.frame to be imported into the REDCap project. Required.
redcap_uri
The URI (uniform resource identifier) of the REDCap project. Required.
token
The user-specific string that serves as the password for a project. Required.
verbose
A boolean value indicating if messages should be printed to the R console during the operation. The verbose output might contain sensitive information (e.g. PHI), so turn this off if the output might be visible somewhere public. Optional.
config_options
A list of options to pass to POST method in the httr package. See the details in redcap_read_oneshot() Optional.

Value

Currently, a list is returned with the following elements,
  1. success: A boolean value indicating if the operation was apparently successful.
  2. status_code: The http status code of the operation.
  3. outcome_message: A human readable string indicating the operation's outcome.
  4. records_affected_count: The number of records inserted or updated.
  5. affected_ids: The subject IDs of the inserted or updated records.
  6. elapsed_seconds: The duration of the function.
  7. raw_text: If an operation is NOT successful, the text returned by REDCap. If an operation is successful, the `raw_text` is returned as an empty string to save RAM.

Details

The `REDCapR' package includes a recent version of the Bundle of CA Root Certificates from the official cURL site. This version is used by default, unless the `cert_location` parameter is given another location.

Currently, the function doesn't modify any variable types to conform to REDCap's supported variables. See validate_for_write for a helper function that checks for some common important conflicts.

References

The official documentation can be found on the `API Help Page` and `API Examples' pages on the REDCap wiki (ie, https://iwg.devguard.com/trac/redcap/wiki/ApiDocumentation and https://iwg.devguard.com/trac/redcap/wiki/ApiExamples). If you do not have an account for the wiki, please ask your campus REDCap administrator to send you the static material.

The official cURL site discusses the process of using SSL to verify the server being connected to.

Examples

Run this code
## Not run: 
# #Define some constants
# uri  <- "https://bbmc.ouhsc.edu/redcap/api/"
# token <- "D70F9ACD1EDD6F151C6EA78683944E98"
# 
# # Read the dataset for the first time.
# result_read1 <- redcap_read_oneshot(redcap_uri=uri, token=token)
# ds1 <- result_read1$data
# ds1$telephone
# # The line above returns something like this (depending on its previous state).
# # [1] "(432) 456-4848" "(234) 234-2343" "(433) 435-9865" "(987) 654-3210" "(333) 333-4444"
# 
# # Manipulate a field in the dataset in a VALID way
# ds1$telephone <- sprintf("(405) 321-%1$i%1$i%1$i%1$i", seq_len(nrow(ds1)))
# 
# ds1 <- ds1[1:3, ]
# ds1$age <- NULL; ds1$bmi <- NULL #Drop the calculated fields before writing.
# result_write <- REDCapR::redcap_write_oneshot(ds=ds1, redcap_uri=uri, token=token)
# 
# # Read the dataset for the second time.
# result_read2 <- redcap_read_oneshot(redcap_uri=uri, token=token)
# ds2 <- result_read2$data
# ds2$telephone
# # The line above returns something like this.  Notice only the first three lines changed.
# # [1] "(405) 321-1111" "(405) 321-2222" "(405) 321-3333" "(987) 654-3210" "(333) 333-4444"
# 
# # Manipulate a field in the dataset in an INVALID way.  A US exchange can't be '111'.
# ds1$telephone <- sprintf("(405) 111-%1$i%1$i%1$i%1$i", seq_len(nrow(ds1)))
# 
# # This next line will throw an error.
# result_write <- REDCapR::redcap_write_oneshot(ds=ds1, redcap_uri=uri, token=token)
# result_write$raw_text
# ## End(Not run)

Run the code above in your browser using DataLab