file_name: The name of the file where the downloaded file is saved. If empty the original name of the file will be used and saved in the default directory. Optional.
directory: The directory where the file is saved. By default current directory. Optional
overwrite: Boolean value indicating if existing files should be overwritten. Optional
token: The user-specific string that serves as the password for a project. Required.
record: The record ID where the file is to be imported. Required
field: The name of the field where the file is saved in REDCap. Required
event: The name of the event where the file is saved in REDCap. Optional
repeat_instance: (only for projects with repeating instruments/events) The repeat instance number of the repeating event (if longitudinal) or the repeating instrument (if classic or longitudinal). Default value is '1'. Optional
verbose: A boolean value indicating if messages should be printed to the R console during the operation. Optional.
config_options: A list of options passed to httr::POST(). See details at httr::httr_options(). Optional.
handle_httr: The value passed to the handle parameter of httr::POST(). This is useful for only unconventional authentication approaches. It should be NULL for most institutions. Optional.
Returns
Currently, a list is returned with the following elements,
success: A boolean value indicating if the operation was apparently successful.
outcome_message: A human readable string indicating the operation's outcome.
records_affected_count: The number of records inserted or updated.
affected_ids: The subject IDs of the inserted or updated records.
elapsed_seconds: The duration of the function.
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.
file_name: The name of the file persisted to disk. This is useful if the name stored in REDCap is used (which is the default).
Details
For files in a repeating instrument, don't specify repeating_instrument. The server only needs field (name) and repeating_instance.
The function redcap_download_file_oneshot() is soft-deprecated as of REDCapR 1.2.0. Please rename to redcap_file_download_oneshot().
Examples
## Not run:uri <-"https://redcap-dev-2.ouhsc.edu/redcap/api/"token <-"F9CBFFF78C3D78F641BAE9623F6B7E6A"# simple-writerecord <-1field <-"mugshot"# event <- "" # only for longitudinal projectsresult_1 <- REDCapR::redcap_file_download_oneshot( record = record, field = field, redcap_uri = uri, token = token
)base::unlink("mugshot-1.jpg")(full_name <- base::tempfile(pattern="mugshot", fileext =".jpg"))result_2 <- REDCapR::redcap_file_download_oneshot( file_name = full_name, record = record, field = field, redcap_uri = uri, token = token
)base::unlink(full_name)(relative_name <-"ssss.jpg")result_3 <- REDCapR::redcap_file_download_oneshot( file_name = relative_name, record = record, field = field, redcap_uri = uri, token = token
)base::unlink(relative_name)## End(Not run)