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

Conversation

rich-iannone
Copy link
Member

This addresses a bug (#142) where aggregation function would operate on all columns and retain only the results for the requested columns. The prior behavior easily results in failures when an aggregation function operates on any column with incompatible data.

The PR also adds functionality for grand summaries (#38, #68). If groups == FALSE we obtain a collection of summary rows that operate on all of the data in the table. We can have both groupwise summaries and grand summaries in the same output table. Grand summaries are distinguishable from groupwise summaries by use of a large double border (and placement at the bottom of the table)

Finally, the PR applies several fixes for summary label generation and catches several edge cases. It's both more flexible, less prone to failure, and stops (with nice messages) if some of the stricter rules aren't followed. The documentation has been updated to reflect these changes.

Here's a table using a groupwise summary (across all groups):

sp500 %>%
  dplyr::filter(
    date >= "2015-01-05" &
      date <="2015-01-16"
  ) %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(
    week = paste0(
      "W", strftime(date, format = "%V"))
  ) %>%
  dplyr::select(-adj_close, -volume) %>%
  gt(
    rowname_col = "date",
    groupname_col = "week"
  ) %>%
  summary_rows(
    groups = TRUE,
    columns = vars(open, high, low, close),
    fns = list(
      min = ~min(.),
      max = ~max(.),
      avg = ~mean(.)),
    formatter = fmt_number,
    use_seps = FALSE
  )

groupwise_summary

Here's a table using a grand summary:

sp500 %>%
  dplyr::filter(
    date >= "2015-01-05" &
      date <="2015-01-16"
  ) %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(
    week = paste0(
      "W", strftime(date, format = "%V"))
  ) %>%
  dplyr::select(-adj_close, -volume) %>%
  gt(
    rowname_col = "date",
    groupname_col = "week"
  ) %>%
  summary_rows(
    groups = FALSE,
    columns = vars(open, high, low, close),
    fns = list(
      min = ~min(.),
      max = ~max(.),
      avg = ~mean(.)),
    formatter = fmt_number,
    use_seps = FALSE
  )

grand_summary

Fixes #38
Fixes #68
Fixes #142

@rich-iannone
Copy link
Member Author

rich-iannone commented Feb 21, 2019

Some design considerations:

  • columns should default to TRUE (this has the same effect as NULL: including all columns)
  • groups as FALSE should no-op (NULL means grand summary, TRUE is all groups, c() specifies individual groups)
  • a location helper function for grand summary rows is necessary as are CSS rules for the new content areas

@jcheng5 please feel free to add anything I missed or refine what's here.

@rich-iannone
Copy link
Member Author

What if there are no groups but we call summary_rows() (and don't set groups = NULL)? I think that instead of stopping we should just provide the grand summary.

@rich-iannone rich-iannone merged commit 85a9e74 into master Apr 24, 2019
@rich-iannone rich-iannone deleted the summary-rows-changes branch April 24, 2019 23:03
rich-iannone added a commit that referenced this pull request Apr 25, 2019
* master:
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
rich-iannone added a commit that referenced this pull request Apr 26, 2019
* master:
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
rich-iannone added a commit that referenced this pull request Apr 26, 2019
* master:
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
rich-iannone added a commit that referenced this pull request Apr 27, 2019
* master:
  Use webshot to generate images of HTML tables (#257)
  Rewritten vignette for adding summary rows (#273)
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
rich-iannone added a commit that referenced this pull request Apr 27, 2019
* master: (37 commits)
  Use webshot to generate images of HTML tables (#257)
  Rewritten vignette for adding summary rows (#273)
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
  Include option to hide all column labels (#237)
  Refactoring of formatter functions (#232)
  Improvement to the handling of a `pattern` in most `fmt*()` functions (#95)
  pkgdown cleanup (#226)
  Make argument names in `tab_options()` more consistent with terminology (#221)
  dplyr::data_frame deprecated (#195)
  Remove a unicode character from roxygen documentation (#220)
  Try again, this time with `travis encrypt --com`
  Trying again with github token (#223)
  Use jcheng5 GitHub PAT instead of rich-iannone (#222)
  Update README (#219)
  Fix for `fmt_date()` that allows `Date` columns to work (#203)
  Remove check on macOS
  ...
rich-iannone added a commit that referenced this pull request Apr 27, 2019
* master:
  Use webshot to generate images of HTML tables (#257)
  Rewritten vignette for adding summary rows (#273)
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
rich-iannone added a commit that referenced this pull request Apr 27, 2019
* master:
  Use webshot to generate images of HTML tables (#257)
  Rewritten vignette for adding summary rows (#273)
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
rich-iannone added a commit that referenced this pull request Apr 27, 2019
* master:
  Use webshot to generate images of HTML tables (#257)
  Rewritten vignette for adding summary rows (#273)
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
  Include option to hide all column labels (#237)
rich-iannone added a commit that referenced this pull request May 8, 2019
* master:
  Adding the `currency()` helper function for specifying custom currencies (#281)
  Enable table striping options (#236)
  Path expand all file inputs (#278)
  Use webshot to generate images of HTML tables (#257)
  Rewritten vignette for adding summary rows (#273)
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
  Include option to hide all column labels (#237)
  Refactoring of formatter functions (#232)
  Improvement to the handling of a `pattern` in most `fmt*()` functions (#95)
  pkgdown cleanup (#226)
  Make argument names in `tab_options()` more consistent with terminology (#221)
  dplyr::data_frame deprecated (#195)
  Remove a unicode character from roxygen documentation (#220)
rich-iannone added a commit that referenced this pull request May 9, 2019
* master: (44 commits)
  Have the table ID be settable, random, or absent in `gt()` (#286)
  Adding the `currency()` helper function for specifying custom currencies (#281)
  Enable table striping options (#236)
  Path expand all file inputs (#278)
  Use webshot to generate images of HTML tables (#257)
  Rewritten vignette for adding summary rows (#273)
  Move roxygen documentation to Markdown (#253)
  Store empty-string value in `sep` vector (#274)
  Bugfixes and improvements to `summary_rows()` (#175)
  Modify _travis.yml (#263)
  Make several refactoring improvements to some `format_*()` functions (#244)
  Include option to hide all column labels (#237)
  Refactoring of formatter functions (#232)
  Improvement to the handling of a `pattern` in most `fmt*()` functions (#95)
  pkgdown cleanup (#226)
  Make argument names in `tab_options()` more consistent with terminology (#221)
  dplyr::data_frame deprecated (#195)
  Remove a unicode character from roxygen documentation (#220)
  Try again, this time with `travis encrypt --com`
  Trying again with github token (#223)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants