R/save_data.R

Defines functions save_data

Documented in save_data

#' Save Data
#'
#' @param data
#' @param dttype
#' @param consort
#' @param cohort
#' @param dtset
#' @param dtlevel
#'
#' @return
#' @export
#'
#' @examples
save_data <- function( data,
                       dttype    = NULL,
                       consort   = NULL,
                       cohort    = NULL,


                       dtset     = "rnaseq",
                       dtlevel   = "gene_expression"
)
{
  if( is.null(dttype)) stop("Please, provide the datatype (pheno, counts, ...)")
  if( is.null(consort)) stop("Please, provide the Consortium (EBOVAC, EBOPLUS, VEBCON )")
  if( is.null(cohort)) stop("Please, provide the Cohort (Geneva, USA, ...)")

  fdir = file.path("data/clean", consort, cohort, dtlevel, dtset)
  if(!dir.exists(fdir)) dir.create(fdir, recursive = T, showWarnings = F)
  fname = paste0(dttype, "_", cohort, ".csv")
  fpath = file.path(fdir, fname)
  data.table::fwrite(data, fpath, row.names = F, quote = F, sep = ',', dec = '.')
}
FernandoMarcon/REbola documentation built on April 4, 2022, 12:49 a.m.