View source: R/data_manipulation_export.R
export_data | R Documentation |
Exports structured SL4 or HAR data to multiple file formats, including CSV, Stata, TXT, RDS, and XLSX. Supports nested lists, automatic subfolder creation, and multi-sheet Excel exports.
export_data(
data,
output_path,
format = "csv",
prefix = "",
create_subfolder = FALSE,
multi_sheet_xlsx = FALSE,
xlsx_filename = NULL,
report_output = FALSE
)
data |
A list or data frame. The SL4 or HAR data to export. |
output_path |
Character. The base output directory or file path. |
format |
Character. The export format ( |
prefix |
Character. An optional prefix added to exported file names. Default is |
create_subfolder |
Logical. If |
multi_sheet_xlsx |
Logical. If TRUE, exports lists as multi-sheet XLSX files. |
xlsx_filename |
An optional filename for the XLSX file (used when |
report_output |
Logical. If TRUE, generates an export report. |
Supports exporting data in "csv"
, "stata"
, "txt"
, "rds"
, and "xlsx"
formats.
Handles nested lists and exports each data frame individually.
Optionally creates subfolders for each format (create_subfolder = TRUE
).
Customizes file names using prefix
.
When multi_sheet_xlsx = TRUE, all exported data is stored in a single Excel workbook, with each dataset as a separate sheet.
If exporting to Stata ("stata"
format), column names containing .
will be replaced with _
to ensure compatibility.
If multi_sheet_xlsx = TRUE
, list elements are exported as separate sheets in a single XLSX file.
The function creates necessary directories if they do not exist.
A list containing the file paths of the exported data.
Pattawee Puangchit
pivot_data
, get_data_by_var
, get_data_by_dims
# Import sample data:
sl4_data <- load_sl4x(system.file("extdata", "TAR10.sl4", package = "HARplus"))
# Extract data
data_multiple <- get_data_by_var(c("qo", "pca"), sl4_data)
# Export
export_data(data_multiple, file.path(tempdir(), "output_directory"),
format = c("csv", "xlsx", "stata", "txt", "rds"),
create_subfolder = TRUE,
multi_sheet_xlsx = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.