Title: | Present Data with Style |
---|---|
Description: | Consists of custom wrapper functions using packages 'openxlsx', 'flextable', and 'officer' to create highly formatted MS office friendly output of your data frames. These viewer friendly outputs are intended to match expectations of professional looking presentations in business and consulting scenarios. The functions are opinionated in the sense that they expect the input data frame to have certain properties in order to take advantage of the automated formatting. |
Authors: | Harrison Tietze [aut, cre] |
Maintainer: | Harrison Tietze <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2 |
Built: | 2025-02-09 04:31:36 UTC |
Source: | https://github.com/harrison4192/presenter |
finish excel workbook
finish_excel_wb(wb, wb_name)
finish_excel_wb(wb, wb_name)
wb |
wb |
wb_name |
wb name |
an excel file
Number formatters to apply to a column in a dataframe. Helpful for displaying tibbles in console or in conjunction
with make_flextable
.
Based off the formattable package.
format_number(tbl, ..., digits = 0) format_percent(tbl, ..., digits = 0) format_currency(tbl, ..., symbol = "yen", digits = 0)
format_number(tbl, ..., digits = 0) format_percent(tbl, ..., digits = 0) format_currency(tbl, ..., symbol = "yen", digits = 0)
tbl |
dataframe |
... |
tidyselect. |
digits |
integer. trailing digits |
symbol |
chr. currency symbol |
format_number
formats a number accounting style by inserting commas. default selection is integer columns
format_percent
formats a number as a percentage. default selection is numeric columns in between -1 and 1.
format_currency
formats a monetary value with the currency symbol. default currency symbol is yen.
dataframe
dataframe
tibble::tibble( y = seq(1000L, 10000L, by = 1000L), z = c(-.59, -.23, -.11, 0, .1, .21, .3, .4, .6, .9), w = c(.1, 1.4, .23, -.10, 0, -2.3, .2,.3,.4,.5)) -> tbl1 tbl1 # automatically formats the integer column tbl1 %>% format_number() # automatically formats to yen tbl1 %>% format_currency(y) # automatically detects columns between -1 and 1 to convert to percentages tbl1 %>% format_percent() # select specific columns to convert. tbl1 %>% format_percent(z, w)
tibble::tibble( y = seq(1000L, 10000L, by = 1000L), z = c(-.59, -.23, -.11, 0, .1, .21, .3, .4, .6, .9), w = c(.1, 1.4, .23, -.10, 0, -2.3, .2,.3,.4,.5)) -> tbl1 tbl1 # automatically formats the integer column tbl1 %>% format_number() # automatically formats to yen tbl1 %>% format_currency(y) # automatically detects columns between -1 and 1 to convert to percentages tbl1 %>% format_percent() # select specific columns to convert. tbl1 %>% format_percent(z, w)
this function captures the name of an object piped into a function, and returns as a string. Powers the automatic naming found in presenter.
get_piped_name(object, default_name = "Table")
get_piped_name(object, default_name = "Table")
object |
an object |
default_name |
string Attempts to return this string if an error occurs. |
string
#necessary to specify this option when using get_piped_name in knitr options(rlang_trace_top_env = rlang::current_env()) ### works if the object is piped or given as an argument iris %>% get_piped_name() get_piped_name(iris) ### can even extract name from multistep pipes iris %>% dplyr::select(1:3) %>% get_piped_name() ### can be placed inside other functions to capture the name and save it find_name <- function(x){ get_piped_name() -> new_name new_name } iris %>% dplyr:select(1:3) %>% find_name()
#necessary to specify this option when using get_piped_name in knitr options(rlang_trace_top_env = rlang::current_env()) ### works if the object is piped or given as an argument iris %>% get_piped_name() get_piped_name(iris) ### can even extract name from multistep pipes iris %>% dplyr::select(1:3) %>% get_piped_name() ### can be placed inside other functions to capture the name and save it find_name <- function(x){ get_piped_name() -> new_name new_name } iris %>% dplyr:select(1:3) %>% find_name()
is_percentage
is_percentage(x)
is_percentage(x)
x |
numeric vector |
logical
c(.1, 0, .5) %>% is_percentage
c(.1, 0, .5) %>% is_percentage
Create Excel
make_excel( df, last_id_col = NULL, header_word = NULL, widths = 13, random_color_seed = 1 )
make_excel( df, last_id_col = NULL, header_word = NULL, widths = 13, random_color_seed = 1 )
df |
data frame |
last_id_col |
index of last id col |
header_word |
character vector of header words |
widths |
col widths |
random_color_seed |
seed for random color scheme |
an excel file
create excel wb
make_excel_wb( wb = NULL, object, last_id_col = NULL, header_word = NULL, widths = 13, random_color_seed = 1 )
make_excel_wb( wb = NULL, object, last_id_col = NULL, header_word = NULL, widths = 13, random_color_seed = 1 )
wb |
wb |
object |
object |
last_id_col |
index of last id col |
header_word |
character vector of header words |
widths |
col widths |
random_color_seed |
seed for random color scheme |
excel wb object
Turns a data frame into a flextable
make_flextable( df, header_words = NULL, last_id_col = NULL, merge_col_indices = NULL, dbl_digits = 2, theme = c("zebra_blue", "zebra_gold", "tron", "vader", "vanilla", "booktabs", "alafoli") )
make_flextable( df, header_words = NULL, last_id_col = NULL, merge_col_indices = NULL, dbl_digits = 2, theme = c("zebra_blue", "zebra_gold", "tron", "vader", "vanilla", "booktabs", "alafoli") )
df |
data frame |
header_words |
header words. Takes a character vector of header words. will be automatically generate via a heuristic if left NULL. can be completely disabled by the string "disable" |
last_id_col |
last id col |
merge_col_indices |
merge specific column indices |
dbl_digits |
integer. how many trailing digits should be displayed on dbls |
theme |
string to choose a preselected theme |
a flextable
If col2 is not supplied, will make a frequency table for 1 column.
make_pivot_table( tbl, col1, col2 = NULL, show_totals = TRUE, show_percentages = c("none", "all", "row", "col"), show_chi_test = FALSE, theme = c("zebra_blue", "zebra_gold", "tron", "vader", "vanilla", "booktabs", "alafoli"), tbl_nm = NULL, arrange_desc = TRUE )
make_pivot_table( tbl, col1, col2 = NULL, show_totals = TRUE, show_percentages = c("none", "all", "row", "col"), show_chi_test = FALSE, theme = c("zebra_blue", "zebra_gold", "tron", "vader", "vanilla", "booktabs", "alafoli"), tbl_nm = NULL, arrange_desc = TRUE )
tbl |
a data frame to pivot |
col1 |
unquoted col 1 |
col2 |
unquoted col 2 |
show_totals |
logical; show row and col totals |
show_percentages |
string; denominator to use when calculating percentages |
show_chi_test |
logical; show results of chi squared test in footnote |
theme |
string to choose a predefined theme |
tbl_nm |
string to name table. If not given, automatically defaults to table name. |
arrange_desc |
param for single col pivot table. if True arranges table by decreasing n size |
a flextable
A table can be piped in to this function to be sent to a new ppt slide. Can be called with no arguments, then a new ppt is created named after the table. If output_file is specified, table is sent to a new slide on an existing powerpoint.
make_powerpoint( tbl, output_file = NULL, layout = "Two Content", master = "Office Theme", show = TRUE )
make_powerpoint( tbl, output_file = NULL, layout = "Two Content", master = "Office Theme", show = TRUE )
tbl |
a data frame, flextable, or a list thereof |
output_file |
path to existing ppt |
layout |
master layout |
master |
master theme |
show |
logical to open the ppt |
none
Export a file to excel with minimal formatting and minimal effort.
make_simple_excel(object, show = TRUE)
make_simple_excel(object, show = TRUE)
object |
a data frame or list thereof |
show |
logical. open excel upon completion? |
an .xlsx file
Wrapper around base r 't()' that returns a tibble. Transposes a data frame, intended for use on the output of a dplyr::summarize operation
pivot_summary(sumr, ...)
pivot_summary(sumr, ...)
sumr |
A tibble |
... |
an optional tidyselect specification of grouping columns to pivot |
for an ungrouped summarize, ... argument can be left empty for a grouped summarize, use column names or tidyselect to pivot the group names. Multiple groups will be concatenated before pivoting.
a tibble