Learn R Programming

R.AlphA.Home (version 2.0.2)

quickExport: Quick Export of Data to Excel with Column Padding

Description

Exports a data frame to an Excel file with optional column padding to ensure a consistent number of columns. This function combines data export functionality with column padding, making it particularly useful for creating Excel files that maintain the same structure across different datasets, especially when used with pivot tables.

Usage

quickExport(
  data,
  sheetName = "data_",
  saveDir = root(),
  saveName = "tmp_export.xlsx",
  nCols = 100,
  colPrefix = "x_",
  overwrite = TRUE
)

Value

No explicit return value. The function writes an Excel file to the specified location and prints a message with the file path.

Arguments

data

A data frame to be exported to Excel.

sheetName

A character string specifying the name of the Excel sheet. Default is "data_".

saveDir

A character string specifying the directory path where the file will be saved. Default uses root() function.

saveName

A character string specifying the filename for the Excel file. Default is "tmp_export.xlsx".

nCols

An integer specifying the total number of columns required after padding. Default is 100.

colPrefix

A character string used as the prefix for the names of dummy columns added during padding. Default is "x_".

overwrite

A logical value indicating whether to overwrite existing files. Default is TRUE.

Examples

Run this code
if (FALSE) {
# Basic usage with default parameters
df <- data.frame(name = c("Alice", "Bob"), age = c(25, 30))
quickExport(df, sheetName = "employees", saveName = "employee_data.xlsx")

# Custom column padding and file location
sales_data <- data.frame(product = c("A", "B"), sales = c(100, 200))
quickExport(sales_data, nCols = 50, colPrefix = "col_",
           saveName = "sales_report.xlsx", overwrite = FALSE)
}

Run the code above in your browser using DataLab