Provides an output of datasets to view through the user's default spreadsheet program.
Usage
xl(
...,
.path = NULL,
.open = TRUE,
.quiet = TRUE,
.sheet_titles = stringr::str_to_title,
.dataframe_spec = NULL,
.tabname_spec = list(sep = ".", pad = ".", name_spec = "{inner}"),
.workbook_spec = list(asTable = TRUE, zoom = 70, withFilter = TRUE),
.return = list("workbook", "savepath", "tibbles", "boolean", "all")
)
Arguments
- ...
A dataframe, list of dataframes, or inputs coercible to one or more dataframes.
- .path
Optional path to save a copy of the workbook output. Uses
here::here()
for savepath completion. If.path
does not end in '.xlsx', automatically adds the suffix. If.path
is not specified, workbook is saved only momentarily in an auto-named temp file. Always creates the specified directory location.- .open
If
FALSE
, workbook will not open after being written.- .quiet
If
FALSE
, echoes function messages.- .sheet_titles
NULL
, a character vector the same length as the number of spreadsheets, or a purrr-style function or formula to apply to the default input names. The default is function:stringr::str_to_title()
.- .dataframe_spec
NULL
(default), or a purrr-style function to apply across all dataframes; e.g.~janitor::clean_names(., case = 'title'))
orjanitor::clean_names
to titlecase or snakecase fieldnames.- .tabname_spec
a list that allows the user to define tab labeling arguments: sep = ".", pad = ".", and name_spec = "inner"
- .workbook_spec
a list of arguments to pass to
openxlsx::buildWorkbook()
, e.g.list(asTable = TRUE, orientation = 'landscape', zoom = 100, startRow = 7)
- .return
return (invisibly) one of 'workbook' (default), 'savepath', 'tibbles', or 'boolean' for workbook write success/failure. If 'all' returns all possibilities in a named list.
Value
The side-effect, a workbook of spreadsheets, is the primary output of this function.
The direct-return output is determined by the input parameter .return
denoting
whether to return the openxlsx
workbook-object, the list of input data cast as
tibbles, or the save path. Any output is returned invisibly.
Details
If you use quick keys, the function set_xlr_key_chords()
will assign
ctrl + alt + shift + l
to the function xl()
. The quick keys allow you to
open a spreadsheet by highlighting an expression or variable within an RStudio
text editor, and then pressing all 3 control keys ctrl + alt + shift
as well
as the letter L
to 'launch' a spreadsheet.
Examples
if (FALSE) {
xl('hi')
xl(mtcars, iris)
xl(iris, iris)
xl(mtcars, iris, .workbook_spec = list(asTable = FALSE, orientation = 'landscape', name = NULL))
xl(mtcars, .sheet_titles = NULL)
iris |> splitter(Species) |> xl(.workbook_spec = list(startRow = c(6,4,2), zoom = 110))
iris |> splitter(Species) |> xl(.sheet_titles=c('SMALL',NA,'LARGE'))
dplyr::starwars |> xl()
dplyr::starwars |> splitter(eye_color) |> xl(.sheet_titles = toupper)
}