Exports a dataset to an Excel file with both raw data and a generated pivot table.
Usage
pivot_table_with_filter(
data,
filter = NULL,
rows = NULL,
cols = NULL,
data_fields = "Value",
raw_sheet_name = "RawData",
pivot_sheet_name = "PivotTable",
dims = "A3",
export = TRUE,
output_path = getwd(),
workbook_name = "GTAP_PivotTable.xlsx"
)
Arguments
- data
Data frame. The dataset to be exported.
- filter
Character vector (optional). Columns to be used as filter fields in the pivot table.
- rows
Character vector (optional). Columns to be used as row fields in the pivot table.
- cols
Character vector (optional). Columns to be used as column fields in the pivot table.
- data_fields
Character. The data field(s) to be summarized in the pivot table (default: `"Value"`).
- raw_sheet_name
Character. Name of the sheet containing raw data (default: `"RawData"`).
- pivot_sheet_name
Character. Name of the sheet containing the pivot table (default: `"PivotTable"`).
- dims
Character. Cell reference where the pivot table starts (default: `"A3"`).
- export
Logical. Whether to save the Excel file (default: `TRUE`).
- output_path
Character. Directory where the file should be saved (default: current working directory).
- workbook_name
Character. Name of the output Excel file (default: `"GTAP_PivotTable.xlsx"`).
Details
This function creates an Excel workbook with: - A raw data sheet (`raw_sheet_name`) containing the provided dataset. - A pivot table sheet (`pivot_sheet_name`) generated based on specified row, column, and data fields.
If `export = TRUE`, the function saves the workbook to the specified `output_path`.