This vignette illustrates how to set up table configurations and
generate outputs.
For a complete list of available tables with sample images, see the table
catalog.
This is an example of how to create a structured pivot table suitable for inclusion in academic presentations.
Important:
The report_table
function requires a data list—not a data frame.
This list structure matches the format of
sl4.plot.data
or har.plot.data
, without
delisting individual elements.
This differs from the plotting functions, which use a data frame as input.
Multiple tables can be generated in a single setup using a data
list.
For example, you can generate report tables for all data frames
within sl4.plot.data
in one code block.
report_table(
data_list = sl4.plot.data,
pivot_col = list(REG = "Variable",
'COMM*REG' = "Commodity"),
group_by = list(
REG = c("Experiment", "Region"),
'COMM*REG' = c("Experiment", "Region")),
rename_cols = list("Experiment" = "Scenario"),
total_column = FALSE,
decimal = 4,
subtotal_level = FALSE,
repeat_label = FALSE,
include_units = TRUE,
var_name_by_description = TRUE,
add_var_info = TRUE,
add_group_line = FALSE,
separate_sheet_by = "Unit",
export_table = FALSE,
output_path = NULL,
separate_file = FALSE,
workbook_name = "Comparison Table"
)
var_name_by_description
replaces variable names with
their full descriptions to enhance clarity and give the output a more
academic appearance.
The same report_table
function can be used to generate
decomposition tables, including a total column, as shown in the example
below:
report_table(
data_list = har.plot.data,
pivot_col = list(A = "COLUMN",
E1 = "PRICES"),
group_by = list(
A = list("Experiment", "Region"),
E1 = list("Experiment", "Commodity", "PRICES")
),
rename_cols = list("Experiment" = "Scenario"),
total_column = TRUE,
decimal = 6,
subtotal_level = FALSE,
repeat_label = FALSE,
include_units = TRUE,
var_name_by_description = FALSE,
add_var_info = FALSE,
add_group_line = FALSE,
separate_sheet_by = "Region",
export_table = FALSE,
output_path = NULL,
separate_file = FALSE,
workbook_name = "Decomposition Table"
)
Unlike static tables generated by report_table()
, pivot
tables remain fully interactive in the Excel output. However, they work
with a single data frame at a time (just like the
plotting functions).
This function offers:
Comprehensive Filtering
Add multiple filtering dimensions to enhance flexibility and enable
users to explore the data from different perspectives.
Retention of Raw Data
The raw dataset is included in the Excel file, allowing downstream
users—especially in Excel—to reconstruct or customize pivot tables as
needed.
User-Oriented Design
Ideal for sharing with non-R users, the output is organized for
intuitive exploration and ease of use.
pivot_table_with_filter(
data = sl4.plot.data[["COMM*REG"]],
filter = c("Variable", "Unit"), # Allow filtering by variable type and unit
rows = c("Region", "Commodity"), # Regions and sectors as row fields
cols = c("Experiment"), # Experiments as column fields
data_fields = "Value", # Values to be aggregated
raw_sheet_name = "Raw_Data", # Sheet name for raw data
pivot_sheet_name = "Sector_Pivot", # Sheet name for pivot table
export_table = FALSE,
output_path = NULL,
workbook_name = "Sectoral_Impact_Analysis.xlsx"
)
Sample data used in this vignette is obtained from the GTAPv7 model and utilizes data from the GTAP 11 database. For more details, refer to the GTAP Database Archive.