Learn R Programming

redcapAPI (version 2.8.0)

fromFileRepositoryMethods: Export, Import, and Delete Individual Files from the File Repository

Description

These methods enable the user to export, import, or delete individual files from a REDCap project's file repository.

Usage

exportFromFileRepository(rcon, doc_id, dir = getwd(), dir_create = FALSE, ...)

importToFileRepository(rcon, file, folder_id = numeric(0), ...)

deleteFromFileRepository(rcon, doc_id, ...)

# S3 method for redcapApiConnection exportFromFileRepository( rcon, doc_id, dir = getwd(), dir_create = FALSE, ..., error_handling = getOption("redcap_error_handling"), config = list(), api_param = list() )

# S3 method for redcapApiConnection importToFileRepository( rcon, file, folder_id = numeric(0), ..., refresh = TRUE, error_handling = getOption("redcap_error_handling"), config = list(), api_param = list() )

# S3 method for redcapApiConnection deleteFromFileRepository( rcon, doc_id, ..., refresh = TRUE, error_handling = getOption("redcap_error_handling"), config = list(), api_param = list() )

Value

exportFromFileRepository, importToFileRepository, and deleteFromFileRepository each return a data frame with the columns:

directoryThe directory in which the file is saved.
filenameThe name of the saved file.

Additionally, exportFromFileRepository displays a message with the file path to which the file was saved on the local computer.

importToFileRepository displays a message with the path in the file repository to which the file is imported.

deleteFromFileRepository displays a message with the path on the file repostiory from which the file was deleted.

Arguments

rcon

A redcapConnection object.

doc_id

integerish(1). The document ID to be downloaded.

folder_id

integerish(0/1). The ID of the folder into which the file is to be imported. If length is zero, it is imported to the top-level folder.

file

character(1). A file on the local system to be imported to the File Repository.

dir

character(1). A directory on the local system to which the file is to be saved. Defaults to the working directory.

dir_create

logical(1). Create the directory dir if it does not already exist. Defaults to FALSE. If dir does not exist and create = FALSE, an error is thrown.

refresh

logical(1) When TRUE, the cached File Repository data on rcon will be refreshed.

...

Arguments to pass to other methods

error_handling

character(1). One of c("error", "null"). An option for how to handle errors returned by the API. see redcapError().

config

A named list. Additional configuration parameters to pass to httr::POST(). These are appended to any parameters in rcon$config.

api_param

A named list. Additional API parameters to pass into the body of the API call. This provides users to execute calls with options that may not otherwise be supported by redcapAPI.

Functions

  • exportFromFileRepository(): Export a file from the file repository.

  • importToFileRepository(): Import a file to the file repository.

  • deleteFromFileRepository(): Delete a file from the file repository.

Details

When a file is deleted, the file will remain in the Recycle Bin folder for up to 30 days.

See Also

exportFileRepository(),
importFileRepository(),
deleteFileRepository(),
exportFileRepositoryListing(),
createFileRepositoryFolder()

Examples

Run this code
if (FALSE) {
unlockREDCap(connections = c(rcon = "project_alias"), 
             url = "your_redcap_url", 
             keyring = "API_KEYs", 
             envir = globalenv())
             
 
write_to_path <- tempdir()            
             
# Export a file from the repository
exportFromFileRepository(rcon, 
                         doc_id = 12345, 
                         dir = write_to_path)
                         
# Export a file and create the target directory if it does not exist
exportFromFileRepository(rcon, 
                         doc_id = 12345, 
                         dir = write_to_path, 
                         dir_create = TRUE)
                         
# Import a file to the top-level directory of the file repository
importFileToRepository(rcon, 
                       file = "file_to_import.txt")
                       
# Import a file to a specific directory of the file repository
importFileToRepository(rcon, 
                       file = "file_to_import.txt", 
                       folder_id = 678)
                       
# Delete a file from the file repository
deleteFileFromRepository(rcon, 
                         doc_id = 12345)
}
  

Run the code above in your browser using DataLab