Skip to contents

Create a new a11ytable-class object, which is a dataframe that contains all the information needed in your output spreadsheet. In turn, the object created by this function can be used to populate an 'openxlsx' Workbook-class object with the function generate_workbook.

Usage

create_a11ytable(
  tab_titles,
  sheet_types = c("cover", "contents", "notes", "tables"),
  sheet_titles,
  blank_cells = NA_character_,
  sources = NA_character_,
  tables
)

Arguments

tab_titles

Required character vector, one value per sheet. Each title will appear literally on each tab of the final spreadsheet output. Keep brief. Letters and numbers only; use underscores for spaces. For example: 'Cover', 'Contents', 'Notes', 'Table_1'. Will be corrected automatically if non-conforming.

sheet_types

Required character vector, one value per sheet. Sheets that don't contain publication tables ('meta' sheets) should be of type 'contents', 'cover' or 'notes'. Sheets that contain statistical tables of data are type 'tables'.

sheet_titles

Required character vector, one value per sheet. The main title for each sheet, which will appear in cell A1 (top-left corner).

blank_cells

Optional character vector, one value per sheet. A short sentence to explain the reason for any blank cells in the sheet. Most likely to be used with sheet type 'tables'.

sources

Optional character vector, one value per sheet. The origin of the data for a given sheet. Supply as NA_character_ if empty. To be used with sheet type 'tables'.

tables

Required list of data.frames, one per sheet. See details.

Value

An object with classes 'a11ytable', 'tbl' and 'data.frame'.

Details

Formats for data.frames provided as a list to the 'tables' argument, depending on the sheet type.

  • Sheet type 'cover': one row per subsection, with columns for 'Subsection title' and 'Subsection text'. For example, a section with contact details might have 'Contact details' as the subsection title and a telephone number and email address in the body-text column. Use linebreaks (i.e. '\n') to put multiple rows in the same body text. Don't break information into separate spreadsheet rows if they belong in the same subsection).

  • Sheet type 'contents': one row per sheet, two columns suggested at least ('Tab title' and 'Worksheet title').

  • Sheet type 'notes': one row per note, two columns suggested ('Note number', 'Note text'), where notes are in the form '[note 1]'.

  • Sheet type 'tables': a tidy, rectangular data.frame containing the data to be published. It's the user's responsibility to add notes in the form '[note 1]' to column headers, or in a special 'Notes' row.

Examples

if (FALSE) {
# Create an a11ytable with in-built demo dataframe, mtcars_df
x <- create_a11ytable(
    tab_titles   = mtcars_df$tab_title,
    sheet_types  = mtcars_df$sheet_type,
    sheet_titles = mtcars_df$sheet_title,
    blank_cells  = mtcars_df$blank_cells,
    sources      = mtcars_df$source,
)

# Test the object's class
is_a11ytable(x)

# You can also use the RStudio Addin installed with the package to insert a
# an example skeleton containing this function.
}