Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes and improvements to summary_rows() #175

Merged
merged 99 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
f7eb5c3
Add comments
rich-iannone Feb 12, 2019
ccc51c7
Simplify assignment
rich-iannone Feb 12, 2019
07e1d15
Modify comments
rich-iannone Feb 12, 2019
c5dc52e
Simplify assignment
rich-iannone Feb 12, 2019
6ea0cfe
Add `select()` statement
rich-iannone Feb 12, 2019
1ca22f4
Modify object names
rich-iannone Feb 12, 2019
08e00b0
Remove `select()` statement
rich-iannone Feb 12, 2019
21f9416
Refactor function
rich-iannone Feb 12, 2019
cf38abd
Make correction to conditional stmt
rich-iannone Feb 12, 2019
003c8e6
Equate `groups == FALSE` to NULL
rich-iannone Feb 12, 2019
aefd285
Refactor and allow for specialized grand summary grp
rich-iannone Feb 12, 2019
9576790
Append grand summary rows to bottom of body
rich-iannone Feb 12, 2019
d68cad0
Add CSS class for the first grand summary row
rich-iannone Feb 12, 2019
0fc623d
Update tests to reflect new behavior
rich-iannone Feb 12, 2019
d019ae7
Include a `context` argument
rich-iannone Feb 12, 2019
b413c63
Normalize `groups` and stop early if necessary
rich-iannone Feb 12, 2019
cc13f69
Modify special label used for grand summary
rich-iannone Feb 12, 2019
c90387f
Use `rlang::as_closure()` instead of `rlang::as_function()`
rich-iannone Feb 12, 2019
e49daca
Refactor statements that produce summary labels
rich-iannone Feb 12, 2019
cf9f172
Stop function if summary labels are not unique
rich-iannone Feb 12, 2019
65d8d52
Modify call to `create_summary_dfs()`
rich-iannone Feb 12, 2019
bea1c95
Modify call to `create_summary_dfs()`
rich-iannone Feb 12, 2019
09ad1f0
Refactor the `extract_summary()` function
rich-iannone Feb 12, 2019
9ad9df8
Modify roxygen documentation
rich-iannone Feb 12, 2019
2e3fd78
Modify default value of `groups` arg
rich-iannone Feb 12, 2019
003f662
Update help file using roxygen
rich-iannone Feb 12, 2019
5c290ef
Stop function if names are not given for bare fcns
rich-iannone Feb 12, 2019
cd85512
Modify label used
rich-iannone Feb 12, 2019
d4a8f25
Remove background color for stub
rich-iannone Feb 23, 2019
7c79860
Add CSS rule for grand summary rows
rich-iannone Feb 23, 2019
c28b1a9
Apply Sass `font-color` function to summary rows
rich-iannone Feb 23, 2019
f63d264
Add Sass rule for grand summary row color
rich-iannone Feb 23, 2019
8eb2771
Add options and defaults for grand summary rows
rich-iannone Feb 23, 2019
f2f8da0
Add the `cells_grand_summary()` function
rich-iannone Feb 23, 2019
f34c064
Modify default options for `summary_rows()`
rich-iannone Feb 23, 2019
aca9c23
Modify the `tab_options()` function
rich-iannone Feb 23, 2019
836aeb6
Add util functions to support grand summaries
rich-iannone Feb 23, 2019
3369409
Update help files using roxygen
rich-iannone Feb 23, 2019
3de1291
Add to NAMESPACE
rich-iannone Feb 23, 2019
3c9f73c
Modify tests to reflect new behavior
rich-iannone Feb 23, 2019
75f8647
Allow for stub creation when necessary
rich-iannone Feb 23, 2019
de1d452
Add several tests for `summary_rows()`
rich-iannone Feb 25, 2019
6ca4551
Modify roxygen @param statement
rich-iannone Feb 25, 2019
a73a4a7
Modify roxygen @param statement
rich-iannone Feb 25, 2019
44f1ee0
Update help file using roxygen
rich-iannone Feb 25, 2019
491c755
Modify roxygen description text
rich-iannone Feb 25, 2019
bf924c9
Modify roxygen description text
rich-iannone Feb 25, 2019
46bb9f7
Update help file using roxygen
rich-iannone Feb 25, 2019
c56070b
Modify assignment to df
rich-iannone Feb 25, 2019
b22c734
Use `resolve_vars()` to obtain colnames
rich-iannone Feb 26, 2019
896e4fe
Merge with master branch
rich-iannone Feb 26, 2019
637e4e1
Merge with branch `master`
rich-iannone Feb 26, 2019
b63cebb
Obtain and store labels in `summary_rows()`
rich-iannone Feb 27, 2019
f6dacb3
Revise `*.cells_summary` to use multiple expr types
rich-iannone Feb 27, 2019
f6dddbe
Revise `*.cells_grand_summary` to use multiple expr types
rich-iannone Feb 27, 2019
1ade3d8
Modify several testthat tests
rich-iannone Feb 27, 2019
52e050e
Merge branch 'master' into summary-rows-changes
rich-iannone Mar 14, 2019
7a4f0ac
Merge branch 'master' into summary-rows-changes
rich-iannone Mar 29, 2019
6c7d2c9
Update help file using roxygen
rich-iannone Mar 29, 2019
7020695
Simplify statements
rich-iannone Mar 30, 2019
a957dcb
Merge branch 'master' into summary-rows-changes
rich-iannone Apr 12, 2019
1551639
Merge branch 'master' into summary-rows-changes
rich-iannone Apr 21, 2019
f3039e7
Modify roxygen documentation
rich-iannone Apr 21, 2019
e98919e
Update help file using roxygen
rich-iannone Apr 21, 2019
8d8c6a3
Get `labels` from `summary_attrs`
rich-iannone Apr 23, 2019
af26c4b
Assign identifier string to local variable
rich-iannone Apr 23, 2019
80bf52f
Add the `assert_rowgroups()` function
rich-iannone Apr 23, 2019
1c9dd74
Add calls the `assert_rowgroups()` fcn
rich-iannone Apr 23, 2019
39c31e4
Remove statements to obtain row labels
rich-iannone Apr 23, 2019
353ce27
Replace identifier string with local variable
rich-iannone Apr 23, 2019
c216c31
Remove `subset()` statements
rich-iannone Apr 23, 2019
a4b1791
Refactor `lapply()` statements
rich-iannone Apr 23, 2019
6cbcb56
Add tests for `cells_summary()`
rich-iannone Apr 23, 2019
5072ad8
Add tests for `cells_grand_summary()`
rich-iannone Apr 23, 2019
a4e2790
Add tests for `tab_footnote()`
rich-iannone Apr 24, 2019
7b0659b
Use the internal `is_false()` fcn
rich-iannone Apr 24, 2019
a7535f1
Modify the `is_false()` call
rich-iannone Apr 24, 2019
57d6db1
Add several testthat tests
rich-iannone Apr 24, 2019
e3a409b
Add tests for the `tab_style()` fcn
rich-iannone Apr 24, 2019
9088b84
Refactor some `set_style.*()` fcns
rich-iannone Apr 24, 2019
d968fda
Add tests for the `tab_options()` fcn
rich-iannone Apr 24, 2019
08ea4d9
Add several testthat tests
rich-iannone Apr 24, 2019
c4c8833
Merge branch 'master' into summary-rows-changes
rich-iannone Apr 24, 2019
6996614
Refactor the adding of summary location rows
rich-iannone Apr 24, 2019
1b3a8a1
Add the `tidy_sub()` util function
rich-iannone Apr 24, 2019
b5610b0
Add the `context_missing_text()` util function
rich-iannone Apr 24, 2019
835ec9d
Refactor the `cols_merge_range()` function
rich-iannone Apr 24, 2019
11d5245
Use the `context_dash_mark()` function
rich-iannone Apr 24, 2019
895b38f
Use the `context_missing_text()` function
rich-iannone Apr 24, 2019
9858770
Modify the `perform_col_merge()` fcn call
rich-iannone Apr 24, 2019
81d3978
Make corrections to several testthat tests
rich-iannone Apr 24, 2019
0838ad2
Ensure sep is an empty string
rich-iannone Apr 24, 2019
42a240f
Remove unneeded conditional statement
rich-iannone Apr 24, 2019
1fea509
Create `grand_summary_col` variable
rich-iannone Apr 24, 2019
2b837a7
Modify position of check for labels (earlier)
rich-iannone Apr 24, 2019
982150a
Clean up logic of checks for groups
rich-iannone Apr 24, 2019
92cdb2a
Use `lapply()` statement in refactor
rich-iannone Apr 24, 2019
d3cc19d
Do not hardcode HTML formatter
rich-iannone Apr 24, 2019
1a7072f
Use `grand_summary_col` variable
rich-iannone Apr 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(as_raw_html)
export(as_rtf)
export(cells_column_labels)
export(cells_data)
export(cells_grand_summary)
export(cells_group)
export(cells_stub)
export(cells_styles)
Expand Down
6 changes: 4 additions & 2 deletions R/as_rtf.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ as_rtf <- function(data) {

# Perform any necessary column merge operations
col_merge_output <-
perform_col_merge(col_merge, data_df, output_df, boxh_df, columns_df)
perform_col_merge(
col_merge, data_df, output_df, boxh_df, columns_df, context
)

# Rewrite `output_df`, `boxh_df`, and `columns_df` as a result of merging
output_df <- col_merge_output$output_df
Expand All @@ -188,7 +190,7 @@ as_rtf <- function(data) {

# Create the `list_of_summaries` list of lists
list_of_summaries <-
create_summary_dfs(summary_list, data_df, stub_df, output_df)
create_summary_dfs(summary_list, data_df, stub_df, output_df, context)

# Determine if there is a populated stub
stub_available <- is_stub_available(stub_df)
Expand Down
6 changes: 4 additions & 2 deletions R/build_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ build_data <- function(data, context) {

# Perform any necessary column merge operations
col_merge_output <-
perform_col_merge(col_merge, data_df, output_df, boxh_df, columns_df)
perform_col_merge(
col_merge, data_df, output_df, boxh_df, columns_df, context
)

# Rewrite `output_df`, `boxh_df`, and `columns_df` as a result of merging
output_df <- col_merge_output$output_df
Expand All @@ -165,7 +167,7 @@ build_data <- function(data, context) {

# Create the `list_of_summaries` list of lists
list_of_summaries <-
create_summary_dfs(summary_list, data_df, stub_df, output_df)
create_summary_dfs(summary_list, data_df, stub_df, output_df, context)

# Determine if there is a populated stub
stub_available <- is_stub_available(stub_df)
Expand Down
89 changes: 13 additions & 76 deletions R/extract_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,86 +59,23 @@
#' @export
extract_summary <- function(data) {

# Extract all attributes from the data object into `data_attr`
# Extract all attributes from the `data`
# object into `data_attr`
data_attr <- attributes(data)

# Stop function if there are no
# directives to create summary rows
if (is.null(data_attr$summary)) {
stop("There is no summary data frame to extract.", call. = FALSE)
stop("There is no summary list to extract.\n",
"Use the `summary_rows()` function to generate summaries.",
call. = FALSE)
}

# Move original data frame to `data_df`
data_df <- as.data.frame(data)
# Build the `data` using the standard
# pipeline with the `html` context
built_data <- build_data(data = data, context = "html")

# Get the `boxh_df` data frame
boxh_df <- data_attr$boxh_df

# Get the `stub_df` data frame
stub_df <- data_attr$stub_df

# Get the `rows_df` data frame
rows_df <- data_attr$rows_df

# Get the `cols_df` data frame
cols_df <- data_attr$cols_df

# Get the `formats` list
formats <- data_attr$formats

# Get the `arrange_groups` vector
arrange_groups <- data_attr$arrange_groups

# Get the `others_group` vector
others_group <- data_attr$others_group[[1]] %||% NA_character_

# Get the `col_merge` object
col_merge <- data_attr$col_merge

# Get the `summary_list` object
summary_list <- data_attr$summary

# Initialize `output_df`
output_df <- initialize_output_df(data_df)

# Create `output_df` with rendered values
output_df <- render_formats(output_df, data_df, formats, context = "html")

# Move input data cells to `output_df` that didn't have
# any rendering applied during `render_formats()`
output_df <- migrate_unformatted_to_output(data_df, output_df, context = "html")

# Get the reordering df (`rows_df`) for the data rows
rows_df <- get_row_reorder_df(arrange_groups, stub_df)

# Get the `columns_df` data frame for the data columns
columns_df <- get_column_reorder_df(cols_df, boxh_df)

# Reassemble the rows and columns of `data_df` in the correct order
output_df <- reassemble_output_df(output_df, rows_df, columns_df)

# Get the `groups_df` data frame, which is a rearranged representation
# of the stub `groupname` and `rowname` columns
groups_df <- get_groupnames_rownames_df(stub_df, rows_df)

# Replace NA values in the `groupname` column if there is a reserved
# label for the unlabeled group
groups_df[is.na(groups_df[, "groupname"]), "groupname"] <- others_group

# Create the `groups_rows_df` data frame, which provides information
# on which rows the group rows should appear above
groups_rows_df <- get_groups_rows_df(arrange_groups, groups_df)

# Perform any necessary column merge operations
col_merge_output <-
perform_col_merge(col_merge, data_df, output_df, boxh_df, columns_df)

# Rewrite `output_df`, `boxh_df`, and `columns_df` as a result of merging
output_df <- col_merge_output$output_df
boxh_df <- col_merge_output$boxh_df
columns_df <- col_merge_output$columns_df

# Create the `list_of_summaries` list of lists
list_of_summaries <-
create_summary_dfs(summary_list, data_df, stub_df, output_df)

list_of_summaries$summary_df_data_list
# Extract the list of summary data frames
# that contains tidy, unformatted data
built_data$list_of_summaries$summary_df_data_list
}
10 changes: 5 additions & 5 deletions R/format_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -1294,11 +1294,11 @@ fmt_missing <- function(data,
fns = list(
html = function(x) {

if (missing_text == "---") {
missing_text <- "\u2014"
} else if (missing_text == "--") {
missing_text <- "\u2013"
}
missing_text <-
context_missing_text(
missing_text = missing_text,
context = "html"
)

# Any values of `x` that are `NA` get
# `missing_text` as output; any values that
Expand Down
7 changes: 5 additions & 2 deletions R/gt_options_default.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ gt_options_default <- function() {
"table_body_border_bottom_style", TRUE, "table_body", "solid",
"table_body_border_bottom_width", TRUE, "table_body", "2px",
"table_body_border_bottom_color", TRUE, "table_body", "#A8A8A8",
"row_padding", TRUE, "row", "10px",
"row_padding", TRUE, "row", "8px",
"row_striping_include_stub", TRUE, "row", "TRUE",
"row_striping_include_table_body", TRUE, "row", "TRUE",
"summary_row_background_color", TRUE, "summary_row", NA_character_,
"summary_row_padding", TRUE, "summary_row", "6px",
"summary_row_padding", TRUE, "summary_row", "8px",
"summary_row_text_transform", TRUE, "summary_row", "inherit",
"grand_summary_row_background_color", TRUE, "grand_summary_row", NA_character_,
"grand_summary_row_padding", TRUE, "grand_summary_row", "8px",
"grand_summary_row_text_transform", TRUE, "grand_summary_row", "inherit",
"footnote_sep", FALSE, "footnote", "<br />",
"footnote_glyph", FALSE, "footnote", "numbers",
"footnote_font_size", TRUE, "footnote", "90%",
Expand Down
24 changes: 24 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,30 @@ cells_summary <- function(groups = NULL,
cells
}

#' @rdname location_cells
#' @import rlang
#' @export
cells_grand_summary <- function(columns = NULL,
rows = NULL) {

# Capture expressions for the `columns`
# and `rows` arguments
col_expr <- rlang::enquo(columns)
row_expr <- rlang::enquo(rows)

# Create the `cells_grand_summary` object
cells <-
list(
columns = col_expr,
rows = row_expr)

# Apply the `cells_grand_summary` and
# `location_cells` classes
class(cells) <- c("cells_grand_summary", "location_cells")

cells
}

#' Interpret input text as Markdown-formatted text
#' @param text the text that is understood to contain Markdown formatting.
#' @return a character object that is tagged for a Markdown-to-HTML
Expand Down
11 changes: 9 additions & 2 deletions R/modify_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ cols_merge <- function(data,
attr(data, "col_merge") <-
list(
pattern = pattern,
sep = "",
col_1 = col_1)
}

Expand Down Expand Up @@ -885,6 +886,7 @@ cols_merge_uncert <- function(data,
attr(data, "col_merge") <-
list(
pattern = pattern,
sep = "",
col_1 = col_val)
}

Expand Down Expand Up @@ -962,10 +964,11 @@ cols_merge_uncert <- function(data,
#' @export
cols_merge_range <- function(data,
col_begin,
col_end) {
col_end,
sep = "---") {

# Set the formatting pattern
pattern <- "{1} \u2014 {2}"
pattern <- "{1} {sep} {2}"

col_begin <- enquo(col_begin)
col_end <- enquo(col_end)
Expand All @@ -991,6 +994,9 @@ cols_merge_range <- function(data,
attr(data, "col_merge")[["pattern"]] <-
c(attr(data, "col_merge")[["pattern"]], pattern)

attr(data, "col_merge")[["sep"]] <-
c(attr(data, "col_merge")[["sep"]], sep)

attr(data, "col_merge")[["col_1"]] <-
c(attr(data, "col_merge")[["col_1"]], col_begin)

Expand All @@ -999,6 +1005,7 @@ cols_merge_range <- function(data,
attr(data, "col_merge") <-
list(
pattern = pattern,
sep = sep,
col_1 = col_begin)
}

Expand Down
Loading