R/writeDataForImport.R

Defines functions writeDataForImport

Documented in writeDataForImport

#' @name writeDataForImport
#' @title Prepare a Data Frame for Import Through the API
#' 
#' @description Converts a dataframe into a character value in the format
#'   of a CSV for import through the API.
#'   
#' @param data `data.frame` to be imported to the API
#' 

writeDataForImport <- function(data){
  coll <- checkmate::makeAssertCollection()
  
  checkmate::assert_data_frame(x = data, 
                               add = coll)
  
  checkmate::reportAssertions(coll)
  
  output <- 
    utils::capture.output(
      utils::write.csv(data,
                       file = "",
                       na = "",
                       row.names = FALSE)
    )
  
  paste0(output, collapse = "\n")
}

Try the redcapAPI package in your browser

Any scripts or data that you put into this service are public.

redcapAPI documentation built on Sept. 13, 2023, 1:07 a.m.