write_formatted_table: Writes multiple data tables and accompanying notes to an...

View source: R/write_tables.R

write_formatted_tableR Documentation

Writes multiple data tables and accompanying notes to an existing sheet of a workbook object.

Description

Allows writing of multiple tables (e.g quarterly and monthly data) to a single existing sheet in a workbook object. Will write the list of provided tables vertically in order, with a single ruled line and space between individual tables.

Can also be passed strings (e.g. headers or additional notes) in the same list, it will write these as bold text in the first column. Notes should be passed as a vector of strings and will be written at the end of all tables, with one string per line. Cells containing notes will be merged horizontally along the width of the tables above.

Quarterly formatting (a taller row every 4 rows) can be added to specified tables through use of the optional "quarterly format" argument. The function does not create a new sheet, so must be given the name of an existing sheet within the workbook.

Best used with an Excel template read into R using openxlsx::loadWorkbook.

To output the workbook as an Excel file, use openxlsx::saveWorkbook.

Usage

write_formatted_table(
  workbook,
  sheet_name,
  tables,
  notes,
  starting_row,
  quarterly_format = NULL
)

Arguments

workbook

openxlsx workbook object

sheet_name

string. Name of an existing sheet in the workbook object.

tables

a list of data.frame objects to write to the sheet.

notes

a character vector of notes to write to the sheet

starting_row

numeric. Row number on the sheet you would like to start writing the tables at.

quarterly_format

numeric vector. List position of the tables in the tables list to apply quarterly formatting to. Default is NULL.


moj-analytical-services/mojrap documentation built on July 30, 2023, 4:43 p.m.