importRecords {redcapAPI} | R Documentation |
Import Records to a Project
Description
These methods enable the user to import new records or update existing records to a project.
Usage
importRecords(
rcon,
data,
overwriteBehavior = c("normal", "overwrite"),
returnContent = c("count", "ids", "nothing", "auto_ids"),
returnData = FALSE,
logfile = "",
...
)
## S3 method for class 'redcapApiConnection'
importRecords(
rcon,
data,
overwriteBehavior = c("normal", "overwrite"),
returnContent = c("count", "ids", "nothing", "auto_ids"),
returnData = FALSE,
logfile = "",
force_auto_number = FALSE,
...,
batch.size = -1,
error_handling = getOption("redcap_error_handling"),
config = list(),
api_param = list()
)
Arguments
rcon |
A |
data |
A |
overwriteBehavior |
|
returnContent |
|
returnData |
|
logfile |
|
... |
Arguments to pass to other methods |
force_auto_number |
|
batch.size |
|
error_handling |
|
config |
A named |
api_param |
A named |
Details
importRecords
prevents the most common import errors by testing the
data before attempting the import. Namely
Check that all variables in
data
exist in the REDCap data dictionary.Check that the record id variable exists
Force the record id variable to the first position in the data frame (with a warning)
Remove calculated fields (with a warning)
Verify that REDCap date fields are represented in the data frame as either
character
,POSIXct
, orDate
class objects.Determine if values are within their specified validation limits.
See the documentation for validateImport()
for detailed
explanations of the validation.
A 'batched' import is one where the export is performed over a series of API calls rather than one large call. For large projects on small servers, this may prevent a single user from tying up the server and forcing others to wait on a larger job.
BioPortal Fields
Text fields that are validation enabled using the BioPortal Ontology service may be imported by providing the coded value. Importing the coded value does not, however, guarantee that the labeled value will be immediately available. Labels for BioPortal values are cached on the REDCap server in a process that occurs when viewing data in the user interface. Thus, if the label has not be previously cached on the server, the code will be used to represent both the code and the label.
Value
importRecords
, when returnData = FALSE
, returns the content from the
API response designated by the returnContent
argument.
importRecords
, when returnData = TRUE
, returns the
data frame that was internally prepared for import. This data frame has
values transformed from R objects to character values the API will
accept.
See Also
exportRecords()
,
deleteRecords()
,
exportRecordsTyped()
Examples
## Not run:
unlockREDCap(connections = c(rcon = "project_alias"),
url = "your_redcap_url",
keyring = "API_KEYs",
envir = globalenv())
# Import records
NewData <- data.frame(record_id = c(1, 2, 3),
age = c(27, 43, 32),
date_of_visit = rep(Sys.Date(), 3))
importRecords(rcon,
data = NewData)
# Import records and save validation info to a file
NewData <- data.frame(record_id = c(1, 2, 3),
age = c(27, 43, 32),
date_of_visit = rep(Sys.Date(), 3))
importRecords(rcon,
data = NewData,
logfile = "import-validation-notes.txt")
## End(Not run)