R/save.R

Defines functions save_classification

Documented in save_classification

#' Save classification to file
#'
#' @param classification object of type \code{classification}.
#' @param filename the filename of the file to save to. When the extension is
#'   '.csv' or '.CSV' the classification is saved as a CSV file.
#' @param binary save as a binary (RDS) file. Otherwise save as a CSV file.
#'
#' @export
save_classification <- function(classification, filename, binary = TRUE) {
  ext <- tools::file_ext(filename)
  if (tolower(ext) == "csv") {
    binary <- FALSE
    warning("Saving as CSV")
  }
  if (tolower(ext) == "rds" && !binary){
    warning("Saving to an RDS file with binary is FALSE. Saving as CSV.")
  }
  if (binary) {
    saveRDS(classification, file = filename)
  } else {
    classification <- do.call(rbind, classification)
    utils::write.csv(classification, filename, row.names = FALSE)
  }
}
uRos2018/categorical documentation built on May 29, 2019, 9:15 a.m.