Skip to content

Commit

Permalink
Merge branch 'master' into quarto-md-to-html-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-iannone authored Oct 5, 2023
2 parents dae0e47 + 4dab304 commit 51615c1
Show file tree
Hide file tree
Showing 24 changed files with 891 additions and 254 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ tests/testthat/test-table_parts.R
tests/testthat/test-text_transform.R
tests/testthat/test-util_functions.R
tests/testthat/test-utils_formatters.R
tests/testthat/test-utils_plots.R
tests/testthat/test-utils_render_html.R
tests/testthat/test-utils_units.R
tests/testthat/test-utils.R
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ authors:
orcid: https://orcid.org/0000-0002-4064-6012
repository: https://CRAN.R-project.org/package=gt
repository-code: https://github.com/rstudio/gt
url: https://gt.rstudio.com/
url: https://gt.rstudio.com
contact:
- family-names: Iannone
given-names: Richard
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Authors@R: c(
person("Posit Software, PBC", role = c("cph", "fnd"))
)
License: MIT + file LICENSE
URL: https://gt.rstudio.com/, https://github.com/rstudio/gt
URL: https://gt.rstudio.com, https://github.com/rstudio/gt
BugReports: https://github.com/rstudio/gt/issues
Encoding: UTF-8
LazyData: true
Expand Down
28 changes: 17 additions & 11 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Nanoplots

* We can now add in little plots called *nanoplots* to a **gt** table (#299, #515). (#1431, #1439, #1445, #1453)
* We can now add in little plots called *nanoplots* to a **gt** table (#299, #515). (#1431, #1439, #1445, #1453, #1458, #1459, #1461)

* The function `cols_nanoplot()` adds a new column that contains the plots. The data can be obtained from one or more columns in the table. A helper function called `nanoplot_options()` allows for altering the composition and styling of the nanoplots in the new column.

Expand All @@ -14,13 +14,13 @@

## Other great new features

* Brand new rows can be added to a **gt** table with the new `rows_add()` function. The user can supply the new row data through name value pairs. You have control over where they are placed by way of the `.before` and `.after` arguments (new rows are added to the bottom of the table by default). You can also add empty (i.e., all `NA`) rows with the `.n_empty` option. (#1323)
* Brand new rows can be added to a **gt** table with the new `rows_add()` function. The user can supply the new row data through name value pairs. You have control over where they are placed by way of the `.before` and `.after` arguments (new rows are added to the bottom of the table by default). You can also add empty (i.e., all `NA`) rows with the `.n_empty` option (#698). (#1323)

* To complement `rows_add()`, the `cols_add()` function was added. New columns can indeed be added to a **gt** table with this function, which has an interface close to that of `dplyr::mutate()`. (#1367)

* You can now use an empty table as the starting point for a **gt** table. This can be used in conjunction with `cols_add()` and `rows_add()` to build a table piece-by-piece in specific workflows/settings. What constitutes empty tables can be any of: `0 x 0` tables, `0 x n` tables (no rows, some columns), or `n x 0` tables (some rows, no columns; treated the same as `0 x 0` tables). (#1376)

* There is now a way to better express measurement units and we do this in **gt** with something called units notation. With an intuitive and easy-to-learn syntax, **gt** will ensure that any measurement units are formatted correctly no matter what the output type is. We can format units in the table body with `fmt_units()`, we can attach units to column labels with `cols_units()`, and we can integrate units notation in the already-available `cols_label()` and `tab_spanner()` functions (#417, #533). (#1357, #1426)
* There is now a way to better express measurement units and we do this in **gt** with something called units notation. With an intuitive and easy-to-learn syntax, **gt** will ensure that any measurement units are formatted correctly no matter what the output type is. We can format units in the table body with `fmt_units()`, we can attach units to column labels with `cols_units()`, and we can integrate units notation in the already-available `cols_label()` and `tab_spanner()` functions (#417, #533). (#1357, #1426, #1446)

* A very useful new helper function, `from_column()`, has been added so you can fetch values (for compatible arguments) from a column in the input table. For example, if you are using `fmt_scientific()` and the number of significant figures should vary across the values to be formatted, a column containing those values for the `n_sigfig` argument can be referenced by `from_column()`. (#1392, #1393, #1395, #1396, #1399, #1403)

Expand All @@ -36,21 +36,23 @@

## Improvements to the Word output format

* Processing to Word output now escapes HTML in more places. (#1303)
* Processing to Word output now escapes HTML in more places (#1378). (#1303)

* The Word output format now uses the `side` argument present in `summary_rows()` and `grand_summary_rows()` to place the new summary rows either the top or bottom of the row group (with `summary_rows()`) or table as a whole (with `grand_summary_rows()`). (#1325)

* Tables rendered as Word output can now handle the specific case where a table with summary rows doesn't have rownames. (#1325)
* Tables rendered as Word output can now handle the specific case where a table with summary rows doesn't have row names. (#1325)

* Summary rows in Word output tables can now be placed at the top or bottom of a group (or at the top or bottom of the table). (#1402)

* Word output tables can now contain images. This entails compatibility with the `fmt_image()` function, and, images (local and remote) can be inserted through Markdown (#1272). (#1273)

## Documentation enhancements

* The **gt** website has been updated with a slightly different look; section names have been updated for consistency. (#1287, #1340, #1341)
* The **gt** website has been updated with a slightly different look; section names have been updated for consistency (#1419). (#1287, #1340, #1341, #1444)

* We've improved the formatting of arguments in the documentation so that they all have short titles and descriptions regarding expected inputs and default values. This looks great both in the internal R help pages and in the **pkgdown**-generated website. (#1338)
* We've improved the formatting of arguments in the documentation so that they all have short titles and descriptions regarding expected inputs and default values. This looks great both in the internal R help pages and in the **pkgdown**-generated website (#1290). (#1338)

* Several small documentation updates were made, with an emphasis on improving examples. (#1293, #1316, #1324, #1329, #1330, #1331, #1334, #1381, #1383, #1395, #1404)
* Several small documentation updates were made, with an emphasis on improving examples (#1304, #1349, #1369). (#1293, #1316, #1324, #1329, #1330, #1331, #1334, #1381, #1383, #1395, #1404, #1442, #1454)

## Minor improvements and bug fixes

Expand All @@ -62,9 +64,11 @@

* The `cols_merge_range()` function now has a `locale` argument. Range patterns across locales are different (can involve the use of a single hyphen, en dash, em dash, tilde, etc.) and so it does make sense to follow the convention of a locale if provided (#158). (#1423)

* The `fmt_url()` function now has a few more options for adding anchor tag attributes (`"target"`, `"rel"`, `"referrerpolicy"`, and `"hreflang"`). Thanks @elipousson for the work on this! (#1428). (#1452)

* We now have rudimentary support for defining column widths for LaTeX output tables (with `cols_width()`). This accepts length values in 'px' which and automatic conversion to 'pt' values is performed to maximize compatibility with different LaTeX flavors (#634, #851, #1417). (#1371, #1450)

* It's now possible to use background fill colors and perform text coloring and bolding for body cells in LaTeX tables. This is commonly performed through the use of `tab_style()` and `data_color()`. (#1352)
* It's now possible to use background fill colors and perform text coloring and emboldened/italicized text within the body cells of LaTeX tables. This is commonly performed through the use of `tab_style()` and `data_color()` (#84, #869). (#1352)

* The `gtsave()` function now works with `gt_group` objects (usually generated through `gt_split()` or `gt_group()`) (#1354). (#1365)

Expand All @@ -90,16 +94,18 @@

* Fixed an issue with `cols_label_with()` where column names wouldn't be relabeled if the resolved columns were only a subset of the total columns available. (#1326)

* Fixed a LaTeX bug where some characters following a `\midrule` would corrupt the table (#145, #391). (#1390)
* Fixed a LaTeX bug where some characters following a `\midrule` would corrupt the table (#145, #391, #1107, #1182). (#1390)

* Provided a rendering fallback for HTML tables rendered in Quarto where the combination of `fmt_markdown()` and `tab_options(quarto.disable_processing = TRUE)` would incorrectly result in empty cells. (#1455)

* A issue associated with a lack of HTML formatting within interactive tables has been fixed (#1299, #1370, #1384). (#1388)
* A issue associated with a lack of HTML formatting within interactive tables has been fixed (#1299, #1370, #1384, #1443). (#1388)

* Many user-facing error messages have been enhanced using the latest features from the **cli** package. (#1337, thanks @olivroy!)

* Unit tests can now be successfully run on Linux flavors that don't have the `locale` utility (#1214). (#1350, thanks @bastistician!)

* If ever the 'undetermined' (`"und"`) locale is used, it is automatically mapped to the `"en"` locale. (#1394)

* Many unit tests were added for much increased test coverage and many more were modified to increase the speed of running the test suite. (#1291, #1294, #1298, #1350, #1412)

* Added utility functions to extract all examples for regularly building a Quarto website (to do integration testing). (#1344)
Expand Down
156 changes: 133 additions & 23 deletions R/format_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -8652,6 +8652,15 @@ format_units_by_context <- function(x, context = "html") {
#' `as_button = TRUE`). All of these options are by default set to `"auto"`,
#' allowing **gt** to choose appropriate fill, width, and outline values.
#'
#' @param target,rel,referrerpolicy,hreflang *Anchor element attributes*
#'
#' `scalar<character>` // *default:* `NULL`
#'
#' Additional anchor element attributes. For descriptions of each attribute
#' and the allowed values, refer to the [MDN Web Docs reference on the anchor
#' HTML element](
#' https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes).
#'
#' @return An object of class `gt_tbl`.
#'
#' @section Compatibility of formatting function with data values:
Expand Down Expand Up @@ -8884,7 +8893,11 @@ fmt_url <- function(
show_underline = "auto",
button_fill = "auto",
button_width = "auto",
button_outline = "auto"
button_outline = "auto",
target = NULL,
rel = NULL,
referrerpolicy = NULL,
hreflang = NULL
) {

# Perform input object validation
Expand Down Expand Up @@ -9059,7 +9072,8 @@ fmt_url <- function(
button_outline_color <- "#DFDFDF"

if (button_fill %in% c(
"#FFFFFF", "#FFFFFF", "#FAF5EF", "#FAFAFA", "#FFFEFC", "#FBFCFA", "#FBFAF2"
"#FFFFFF", "#FFFFFF", "#FAF5EF", "#FAFAFA",
"#FFFEFC", "#FBFCFA", "#FBFAF2"
)) {
button_outline_style <- "solid"
} else {
Expand Down Expand Up @@ -9112,7 +9126,6 @@ fmt_url <- function(
}
} else {


if (any(grepl("\\[.*?\\]\\(.*?\\)", x_str_non_missing))) {

# Generate labels
Expand Down Expand Up @@ -9152,28 +9165,125 @@ fmt_url <- function(
}
}

add_anchor_attr <- function(
init = NULL,
arg,
nm,
values = NULL,
error_arg = caller_arg(arg),
error_call = caller_env()
) {

if (!is.null(values)) {

arg <-
rlang::arg_match(
arg,
values = values,
error_arg = error_arg,
error_call = error_call
)
}

if (!is_string(arg)) {
cli::cli_abort(
"{.arg {nm}} must be a string, not {.obj_type_friendly {arg}}",
call = error_call
)
}

paste0(init, " ", nm, "=\"", arg, "\"")
}

target <- target %||% "_blank"
target_values <- NULL

if (grepl("^_", target)) {
target_values <- c("_blank", "_self", "_parent", "_top")
}

anchor_attr <-
add_anchor_attr(
arg = target,
nm = "target",
values = target_values
)

if (!is.null(rel)) {

anchor_attr <-
add_anchor_attr(
anchor_attr,
rel,
nm = "rel",
values = c(
"alternate", "author", "bookmark", "external", "help",
"license", "next", "nofollow", "noreferrer", "noopener",
"prev", "search", "tag"
)
)
}

if (!is.null(referrerpolicy)) {

anchor_attr <-
add_anchor_attr(
anchor_attr,
referrerpolicy,
nm = "referrerpolicy",
values = c(
"no-referrer", "no-referrer-when-downgrade", "origin",
"origin-when-cross-origin", "same-origin", "strict-origin",
"strict-origin-when-cross-origin", "unsafe-url"
)
)
}

if (!is.null(hreflang)) {

anchor_attr <-
add_anchor_attr(
anchor_attr,
arg = hreflang,
nm = "hreflang"
)
}

anchor_attr <-
add_anchor_attr(
anchor_attr,
arg = paste0(
"color:", color[1], ";",
"text-decoration:",
if (show_underline) "underline" else "none", ";",
if (show_underline) "text-underline-position: under;" else NULL,
"display: inline-block;",
if (as_button) {
paste0(
"background-color: ", button_fill, ";",
"padding: 8px 12px;",
if (!is.null(button_width)) {
paste0("width: ", button_width, "; text-align: center;")
} else {
NULL
},
"outline-style: ", button_outline_style, "; ",
"outline-color: ", button_outline_color, "; ",
"outline-width: ", button_outline_width, ";"
)
} else {
NULL
}
),
nm = "style"
)

x_str_non_missing <-
paste0(
"<a ",
"href=\"", x_str_non_missing, "\" ",
"target=\"_blank\" ",
"style=\"color:", color[1], ";",
"text-decoration:", if (show_underline) "underline" else "none", ";",
if (show_underline) "text-underline-position: under;" else NULL,
"display: inline-block;",
if (as_button) paste0("background-color: ", button_fill, ";") else NULL,
if (as_button) "padding: 8px 12px;" else NULL,
if (as_button && !is.null(button_width)) paste0("width: ", button_width, "; text-align: center;"),
if (as_button) {
paste0(
"outline-style: ", button_outline_style, "; ",
"outline-color: ", button_outline_color, "; ",
"outline-width: ", button_outline_width, ";"
)
} else {
NULL
},
"\">",
"<a",
" href=\"", x_str_non_missing, "\"",
anchor_attr,
">",
label_str,
"</a>"
)
Expand Down
Loading

0 comments on commit 51615c1

Please sign in to comment.