Skip to content

Commit

Permalink
Merge branch 'master' into cols-widths
Browse files Browse the repository at this point in the history
* master:
  Add the `cells_stubhead_label()` location helper (#276)
  Refactoring of the `tab_options()` function (#288)
  Add the `path` argument to `gtsave()` (#290)
  Refactoring of heading component (#239)
  Use `sass` package from CRAN (not GitHub) (#313)
  • Loading branch information
rich-iannone committed Jul 16, 2019
2 parents a6cb018 + 432dd9f commit 4f97d31
Show file tree
Hide file tree
Showing 100 changed files with 3,306 additions and 2,596 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ Imports:
magrittr (>= 1.5),
rlang (>= 0.3.0),
scales (>= 1.0.0),
sass (>= 0.1.0),
sass (>= 0.1.1),
stringr (>= 1.3.1),
tibble (>= 1.4.2),
tidyr (>= 0.8.2),
tidyselect (>= 0.2.5)
Remotes:
rstudio/sass
Suggests:
knitr,
paletteer,
Expand All @@ -49,6 +47,7 @@ Suggests:
rmarkdown,
rvest,
shiny,
webshot,
xml2
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
62 changes: 5 additions & 57 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ export(adjust_luminance)
export(as_latex)
export(as_raw_html)
export(as_rtf)
export(cell_borders)
export(cell_fill)
export(cell_text)
export(cells_column_labels)
export(cells_data)
export(cells_grand_summary)
export(cells_group)
export(cells_stub)
export(cells_stubhead)
export(cells_styles)
export(cells_summary)
export(cells_title)
Expand Down Expand Up @@ -73,7 +77,7 @@ export(tab_options)
export(tab_row_group)
export(tab_source_note)
export(tab_spanner)
export(tab_stubhead_label)
export(tab_stubhead)
export(tab_style)
export(test_image)
export(text_transform)
Expand All @@ -83,68 +87,12 @@ import(checkmate)
import(rlang)
import(sass)
import(tidyselect)
importFrom(checkmate,test_class)
importFrom(commonmark,markdown_html)
importFrom(commonmark,markdown_latex)
importFrom(commonmark,markdown_text)
importFrom(dplyr,arrange)
importFrom(dplyr,between)
importFrom(dplyr,bind_rows)
importFrom(dplyr,case_when)
importFrom(dplyr,distinct)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,group_vars)
importFrom(dplyr,inner_join)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_at)
importFrom(dplyr,pull)
importFrom(dplyr,rename)
importFrom(dplyr,select)
importFrom(dplyr,slice)
importFrom(dplyr,summarize)
importFrom(dplyr,summarize_all)
importFrom(dplyr,tibble)
importFrom(dplyr,tribble)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(ggplot2,ggsave)
importFrom(glue,glue)
importFrom(grDevices,col2rgb)
importFrom(grDevices,convertColor)
importFrom(grDevices,hcl)
importFrom(htmltools,HTML)
importFrom(htmltools,as.tags)
importFrom(htmltools,doRenderTags)
importFrom(htmltools,findDependencies)
importFrom(htmltools,htmlEscape)
importFrom(htmltools,resolveDependencies)
importFrom(htmltools,save_html)
importFrom(htmltools,tagList)
importFrom(htmltools,tags)
importFrom(magrittr,"%>%")
importFrom(scales,col_factor)
importFrom(scales,col_numeric)
importFrom(stats,na.omit)
importFrom(stats,setNames)
importFrom(stringr,str_detect)
importFrom(stringr,str_extract)
importFrom(stringr,str_match)
importFrom(stringr,str_remove)
importFrom(stringr,str_replace)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_split)
importFrom(stringr,str_trim)
importFrom(tibble,rownames_to_column)
importFrom(tidyr,fill)
importFrom(tidyselect,contains)
importFrom(tidyselect,ends_with)
importFrom(tidyselect,everything)
importFrom(tidyselect,matches)
importFrom(tidyselect,one_of)
importFrom(tidyselect,starts_with)
importFrom(tools,file_ext)
importFrom(utils,globalVariables)
importFrom(utils,head)
62 changes: 47 additions & 15 deletions R/as_latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#' containing the LaTeX code.
#'
#' @param data A table object that is created using the [gt()] function.
#' @import rlang
#' @importFrom dplyr mutate group_by summarize ungroup rename arrange
#' @importFrom stats setNames
#' @examples
#' # Use `gtcars` to create a gt table;
#' # add a header and then export as
Expand Down Expand Up @@ -47,20 +44,34 @@ as_latex <- function(data) {

# Add footnote glyphs to elements of the table columns
boxh_df <-
set_footnote_glyphs_columns(footnotes_resolved, boxh_df, output = "latex")
set_footnote_glyphs_columns(
footnotes_resolved = footnotes_resolved,
boxh_df = boxh_df,
output = "latex"
)

# Add footnote glyphs to the `data` rows
output_df <-
apply_footnotes_to_output(output_df, footnotes_resolved, output = "latex")
apply_footnotes_to_output(
output_df = output_df,
footnotes_resolved = footnotes_resolved,
output = "latex"
)

# Add footnote glyphs to stub group title elements
groups_rows_df <-
set_footnote_glyphs_stub_groups(
footnotes_resolved, groups_rows_df, output = "latex")
footnotes_resolved = footnotes_resolved,
groups_rows_df = groups_rows_df,
output = "latex"
)

# Add footnote glyphs to the `summary` rows
list_of_summaries <-
apply_footnotes_to_summary(list_of_summaries, footnotes_resolved)
apply_footnotes_to_summary(
list_of_summaries = list_of_summaries,
footnotes_resolved = footnotes_resolved
)

# Extraction of body content as a vector ----------------------------------
body_content <- as.vector(t(output_df))
Expand All @@ -71,36 +82,57 @@ as_latex <- function(data) {
row_splits <- split(body_content, ceiling(seq_along(body_content) / n_cols))

# Create a LaTeX fragment for the start of the table
table_start <- create_table_start_l(col_alignment)
table_start <- create_table_start_l(col_alignment = col_alignment)

# Create the heading component of the table
heading_component <-
create_heading_component(
heading, footnotes_resolved, n_cols = n_cols, output = "latex")
heading = heading,
footnotes_resolved = footnotes_resolved,
styles_resolved = styles_resolved,
n_cols = n_cols,
subtitle_defined = subtitle_defined,
output = "latex"
)

# Create the columns component of the table
columns_component <-
create_columns_component_l(
boxh_df, output_df, stub_available, spanners_present,
stubhead_label)
boxh_df = boxh_df,
output_df = output_df,
stub_available = stub_available,
spanners_present = spanners_present,
stubhead = stubhead
)

# Create the body component of the table
body_component <-
create_body_component_l(
row_splits, groups_rows_df, col_alignment, stub_available,
summaries_present, list_of_summaries, n_rows, n_cols)
row_splits = row_splits,
groups_rows_df = groups_rows_df,
col_alignment = col_alignment,
stub_available = stub_available,
summaries_present = summaries_present,
list_of_summaries = list_of_summaries,
n_rows = n_rows,
n_cols = n_cols
)

# Create a LaTeX fragment for the ending tabular statement
table_end <- create_table_end_l()

# Create the footnote component of the table
footnote_component <-
create_footnote_component_l(
footnotes_resolved, opts_df)
footnotes_resolved = footnotes_resolved,
opts_df = opts_df
)

# Create the source note component of the table
source_note_component <-
create_source_note_component_l(source_note)
create_source_note_component_l(
source_note = source_note
)

# If the `rmarkdown` package is available, use the
# `latex_dependency()` function to load latex packages
Expand Down
15 changes: 9 additions & 6 deletions R/as_rtf.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ as_rtf <- function(data) {
# Get the `heading` object
heading <- data_attr$heading

# Get the `stubhead_label` object
stubhead_label <- data_attr$stubhead_label
# Get the `stubhead` object
stubhead <- data_attr$stubhead

# Get the `source_note` object
source_note <- data_attr$source_note
Expand Down Expand Up @@ -242,6 +242,9 @@ as_rtf <- function(data) {
columns_spanners, title_defined, subtitle_defined,
footnotes_df = footnotes_df, styles_df = NULL)

# The styles table is not yet available for RTF
styles_resolved <- NULL

# Add footnote glyphs to elements of the table columns
boxh_df <-
set_footnote_glyphs_columns(footnotes_resolved, boxh_df, output = "rtf")
Expand Down Expand Up @@ -272,7 +275,8 @@ as_rtf <- function(data) {
# Create a heading component of the table and handle any available footnotes
heading_component <-
create_heading_component(
heading, footnotes_resolved, n_cols = n_cols, output = "rtf")
heading, footnotes_resolved, styles_resolved, n_cols,
subtitle_defined, output = "rtf")

# Get the headings
headings <- names(output_df)
Expand All @@ -288,11 +292,10 @@ as_rtf <- function(data) {

# If `stub_available` == TRUE, then replace with a set stubhead
# caption or nothing
if (stub_available &&
length(stubhead_label) > 0 &&
if (stub_available && length(stubhead) > 0 &&
"rowname" %in% headings) {

headings[which(headings == "rowname")] <- stubhead_label$stubhead_label
headings[which(headings == "rowname")] <- stubhead$label

} else if ("rowname" %in% headings) {

Expand Down
18 changes: 11 additions & 7 deletions R/build_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ build_data <- function(data, context) {
"names", "row.names", "class", "boxh_df", "stub_df",
"footnotes_df", "styles_df", "rows_df", "cols_df",
"col_labels", "grp_labels", "arrange_groups", "opts_df",
"formats", "transforms"))
"formats", "transforms")
)

# Move original data frame to `data_df`
data_df <- as.data.frame(data)
Expand Down Expand Up @@ -71,8 +72,8 @@ build_data <- function(data, context) {
# Get and process the `heading` object
heading <- data_attr$heading %>% process_heading(context)

# Get and process the `stubhead_label` object
stubhead_label <- data_attr$stubhead_label %>% process_stubhead_label(context)
# Get and process the `stubhead` object
stubhead <- data_attr$stubhead %>% process_stubhead(context)

# Get and process the `source_note` object
source_note <- data_attr$source_note %>% process_source_notes(context)
Expand Down Expand Up @@ -217,14 +218,16 @@ build_data <- function(data, context) {
resolve_footnotes_styles(
output_df, boxh_df, groups_rows_df, opts_df, arrange_groups,
columns_spanners, title_defined, subtitle_defined,
footnotes_df = footnotes_df, styles_df = NULL)
footnotes_df = footnotes_df, styles_df = NULL
)

# Resolve the styles table
styles_resolved <-
resolve_footnotes_styles(
output_df, boxh_df, groups_rows_df, opts_df, arrange_groups,
columns_spanners, title_defined, subtitle_defined,
footnotes_df = NULL, styles_df = styles_df)
footnotes_df = NULL, styles_df = styles_df
)

list(
data_df = data_df,
Expand All @@ -246,7 +249,7 @@ build_data <- function(data, context) {
heading = heading,
columns_spanners = columns_spanners,
source_note = source_note,
stubhead_label = stubhead_label,
stubhead = stubhead,
stub_components = stub_components,
col_alignment = col_alignment,
col_merge = col_merge,
Expand All @@ -261,5 +264,6 @@ build_data <- function(data, context) {
spanners_present = spanners_present,
summaries_present = summaries_present,
n_rows = n_rows,
n_cols = n_cols)
n_cols = n_cols
)
}
1 change: 0 additions & 1 deletion R/cells_column_labels.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# cells_column_labels

resolve_location.cells_column_labels <- function(loc, data_attr) {

Expand Down
7 changes: 4 additions & 3 deletions R/cells_data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# cells_data

resolve_location.cells_data <- function(loc, data_attr) {

Expand Down Expand Up @@ -30,12 +29,14 @@ to_output_location.cells_data <- function(loc, data_attr) {
columns_df <-
get_column_reorder_df(
cols_df = data_attr$cols_df,
boxh_df = data_attr$boxh_df)
boxh_df = data_attr$boxh_df
)

rows_df <-
get_row_reorder_df(
arrange_groups = data_attr$arrange_groups,
stub_df = data_attr$stub_df)
stub_df = data_attr$stub_df
)

# We shouldn't need to do this, but output_df doesn't match up exactly to
# the colnum_final values due to groupnames/rownames
Expand Down
8 changes: 2 additions & 6 deletions R/cells_stub.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ resolve_location.cells_stub <- function(loc, data_attr) {
resolved <- resolve_cells_stub(data = stub_df, object = loc)

loc$rows <- resolved$rows
# loc$rows <-
# resolve_vars(
# var_expr = loc[["rows"]],
# var_names = stub_df$rowname,
# data_df = stub_df)

class(loc) <- c("resolved", class(loc))

Expand All @@ -25,7 +20,8 @@ to_output_location.cells_stub <- function(loc, data_attr) {
rows_df <-
get_row_reorder_df(
arrange_groups = data_attr$arrange_groups,
stub_df = data_attr$stub_df)
stub_df = data_attr$stub_df
)

loc$rows <- rows_df$rownum_final[loc$rows]

Expand Down
Loading

0 comments on commit 4f97d31

Please sign in to comment.