R/export_excel.R

Defines functions export_excel

Documented in export_excel

#' @title Export data-frames as Microsoft Excel files
#'
#' @description
#' Export data-frames as Microsoft Excel files.
#'
#' To name sheets, set \code{x} to a named list of data-frames.
#'
#' @usage
#' export_excel(x, dirname, rpath)
#'
#' @param x A data-frame, or named list of data-frames that will be sheets in the Excel file.
#' @param dirname A directory above 1) the Excel file and 2) the R file.
#' @param rpath Relative to \code{dirname}, path to the Excel file.
#'
#' @seealso
#' \code{\link{import_excel}}
#'
#' @importFrom writexl write_xlsx
#'
#' @export

export_excel <- function(x,
                         dirname,
                         rpath) {

  path <- zhaoy::path(basename = dirname,
                      rpath)

  writexl::write_xlsx(x = x,
                      path = path,
                      col_names = TRUE,
                      format_headers = FALSE)

}
zhaoy/zhaoy documentation built on Feb. 1, 2024, 7:50 p.m.