xlr_table | R Documentation |
xlr_table
objectCreate 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()
.
xlr_table(x, title = character(), footnote = character())
is_xlr_table(x)
as_xlr_table(x, title = character(), footnote = character())
x |
a data object
|
title |
a string that is the title |
footnote |
a string that is the footnote |
a xlr_table
S3 class
update_theme()
, as_base_r()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.