to_sheet: Write data to sheet (in an openxlsx workbook)

Description Usage Arguments Value Note Author(s) Examples

Description

This function (a very thin wrapper for openxlsx functions) that writes/appends a data.frame to the specified sheet in a loaded openxlsx workbook.

Usage

1
2
to_sheet(df, wb, title = "Table", sheet = "analysis", row = 1L,
  format_style = TRUE, format_values = TRUE, append = TRUE)

Arguments

df

The data to write.

wb

A loaded openxlsx workbook (use openxlsx::loadWorkbook)

title

The title to give to the table (only used if style = TRUE).

sheet

Name of the sheet to write to, will be created if it does not exist.

row

Optional: Also specify the startingrow for writing data.

format_style

Set to FALSE if you do not want styling for the data.

format_values

Set to FALSE and no formatting will be applied based on variable type. With TRUE, character columns will be left justified, numeric will have 1 decimal place, integer 0, and columns with values between 1 and 0 as percentages.

append

Whether or not the function should append or clean the sheet of existing data before writing.

Value

A list containing data.frames matching the sheets in the .xlsx file. If only one sheet is read, the function returns a data.frame instead.

Note

This function requires openxlsx.

Author(s)

Kristian D. Olsen

Examples

1
2
3
wb <- openxlsx::loadWorkbook("test.xlsx")
x %>% to_sheet(wb, sheet = "test", append = FALSE)
openxlsx::saveWorkbook(wb, "test.xlsx", overwrite = TRUE)

itsdalmo/reporttool documentation built on May 18, 2019, 7:11 a.m.