xlr_table: 'xlr_table' object

View source: R/xlr_table.R

xlr_tableR Documentation

xlr_table object

Description

Create a xlr_table S3 object. This is used to create an object that stores formatting information, as well as a title and footnote. This objects makes it easy to convert to an Excel sheet, using write_xlsx(). To edit underlying formatting options use update_theme().

A number of dplyr methods have been implemented for xlr_table, these include mutate, summarise, select, etc. This means you can use these functions on a xlr_table, without losing the xlr_table attributes. You can check if the dplyr function is supported by checking the documentation of the function. Currently, it is not possible to use group_by and a xlr_table, as this would require the implementation of a new class.

You can convert a table back to a data.frame with base type with as_base_r().

Usage

xlr_table(x, title = character(), footnote = character())

is_xlr_table(x)

as_xlr_table(x, title = character(), footnote = character())

Arguments

x

a data object

  • for xlr_table() : a data.frame, or tibble. See notes for further details.

  • for is_xlr_table() : An object

  • for as_xlr_table() a data.frame, or tibble.

title

a string that is the title

footnote

a string that is the footnote

Value

a xlr_table S3 class

See Also

update_theme(), as_base_r()

Examples



library(xlr)
library(dplyr)
# Create a xlr_table, we set the footnotes and the title
# It converts to the xlr types by default
x <- xlr_table(mtcars,
                title = "mtcars is a fun data set",
                footnote = "mtcars is a data set that comes with base R")
# The title and the footnote print to console
x
# You can use mutate and summarise with xlr_tables and they are preserved
x |>
  summarise(mean_mpg = sum(mpg))
# Rename a column
x |>
  rename(new_name = mpg)
# When you want to change how elements of the table look when written using
# write_xlsx, you can update it with update them
x <- x |>
  # make the font bigger
  update_theme(title_format = xlr_format(font_size = 14))
# you must write it in order to see the formatting changes
write_xlsx(x,
             "example.xlsx",
             "A example sheet",
             TOC = FALSE)



xlr documentation built on April 3, 2025, 6:07 p.m.