Skip to content

Commit

Permalink
Merge branch 'master' into stubhead-caption-location
Browse files Browse the repository at this point in the history
* master:
  Refactoring of heading component (#239)
  Use `sass` package from CRAN (not GitHub) (#313)
  Add options related to the table <div> (#285)
  • Loading branch information
rich-iannone committed Jul 11, 2019
2 parents 8261b7b + 2806537 commit 7bf6a7e
Show file tree
Hide file tree
Showing 77 changed files with 2,947 additions and 1,807 deletions.
4 changes: 1 addition & 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 Down
59 changes: 3 additions & 56 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ 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)
Expand Down Expand Up @@ -83,68 +86,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)
22 changes: 11 additions & 11 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 @@ -56,7 +53,8 @@ as_latex <- function(data) {
# 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, groups_rows_df, output = "latex"
)

# Add footnote glyphs to the `summary` rows
list_of_summaries <-
Expand All @@ -76,31 +74,33 @@ as_latex <- function(data) {
# Create the heading component of the table
heading_component <-
create_heading_component(
heading, footnotes_resolved, n_cols = n_cols, output = "latex")
heading, footnotes_resolved, styles_resolved, n_cols,
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)
stubhead_label
)

# 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)
summaries_present, list_of_summaries, n_rows, 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)
create_footnote_component_l(footnotes_resolved, opts_df)

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

# If the `rmarkdown` package is available, use the
# `latex_dependency()` function to load latex packages
Expand Down
6 changes: 5 additions & 1 deletion R/as_rtf.R
Original file line number Diff line number Diff line change
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 Down
12 changes: 8 additions & 4 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 @@ -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 Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions R/compile_scss.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ compile_scss <- function(data, id = NULL) {
sass::sass(
list(
list(element_id = id),
as.list(setNames(gt_options_tbl$value, gt_options_tbl$parameter)),
as.list(stats::setNames(gt_options_tbl$value, gt_options_tbl$parameter)),
sass::sass_file(system_file(file = "css/gt_colors.scss")),
sass::sass_file(system_file(file = "css/gt_styles_default.scss")),
glue::glue(
Expand All @@ -28,5 +28,7 @@ compile_scss <- function(data, id = NULL) {
<<ifelse(has_id, '##{$element_id} {', '')>>
@include gt_styles();
<<ifelse(has_id, '}', '')>>
")))
")
)
)
}
Loading

0 comments on commit 7bf6a7e

Please sign in to comment.