From 90be5f53b8b3a76785ec03f47cc4637e79b1be71 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Tue, 3 Sep 2024 19:34:15 -0400 Subject: [PATCH] Update examples --- R/cols_align.R | 11 ++++++++--- R/cols_hide.R | 18 ++++++++++++------ R/cols_label.R | 12 ++++++++---- R/cols_move.R | 30 ++++++++++++++++++++---------- R/data_color.R | 12 ++++++++---- R/format_data.R | 2 +- man/cols_align.Rd | 11 ++++++++--- man/cols_hide.Rd | 12 ++++++++---- man/cols_label.Rd | 12 ++++++++---- man/cols_move.Rd | 6 ++++-- man/cols_move_to_end.Rd | 12 ++++++++---- man/cols_move_to_start.Rd | 12 ++++++++---- man/cols_unhide.Rd | 6 ++++-- man/data_color.Rd | 12 ++++++++---- man/fmt_flag.Rd | 2 +- 15 files changed, 114 insertions(+), 56 deletions(-) diff --git a/R/cols_align.R b/R/cols_align.R index ffa5a70bdf..5a6a7e96cf 100644 --- a/R/cols_align.R +++ b/R/cols_align.R @@ -78,9 +78,14 @@ #' ```r #' countrypops |> #' dplyr::select(-contains("code")) |> -#' dplyr::filter(country_name == "San Marino") |> -#' dplyr::slice_tail(n = 5) |> -#' gt(rowname_col = "year", groupname_col = "country_name") |> +#' dplyr::filter( +#' country_name == "San Marino", +#' year %in% 2017:2021 +#' ) |> +#' gt( +#' rowname_col = "year", +#' groupname_col = "country_name" +#' ) |> #' cols_align( #' align = "left", #' columns = population diff --git a/R/cols_hide.R b/R/cols_hide.R index cee155b713..b76ae366a2 100644 --- a/R/cols_hide.R +++ b/R/cols_hide.R @@ -68,8 +68,10 @@ #' #' ```r #' countrypops |> -#' dplyr::filter(country_name == "Egypt") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Egypt", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_hide(columns = c(country_code_2, country_code_3)) #' ``` @@ -86,8 +88,10 @@ #' #' ```r #' countrypops |> -#' dplyr::filter(country_name == "Pakistan") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Pakistan", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_hide(columns = c(country_code_3, population)) |> #' tab_footnote( @@ -189,8 +193,10 @@ cols_hide <- function( #' ```r #' tab_1 <- #' countrypops |> -#' dplyr::filter(country_name == "Singapore") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Singapore", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_hide(columns = c(country_code_2, country_code_3)) #' diff --git a/R/cols_label.R b/R/cols_label.R index 7ea7bdbb56..f2e8f6aa3e 100644 --- a/R/cols_label.R +++ b/R/cols_label.R @@ -142,8 +142,10 @@ #' ```r #' countrypops |> #' dplyr::select(-contains("code")) |> -#' dplyr::filter(country_name == "Uganda") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Uganda", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_label( #' country_name = "Name", @@ -164,8 +166,10 @@ #' ```r #' countrypops |> #' dplyr::select(-contains("code")) |> -#' dplyr::filter(country_name == "Uganda") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Uganda", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_label( #' country_name = md("**Name**"), diff --git a/R/cols_move.R b/R/cols_move.R index bc527dc9b8..7485cdb757 100644 --- a/R/cols_move.R +++ b/R/cols_move.R @@ -79,8 +79,10 @@ #' ```r #' countrypops |> #' dplyr::select(-contains("code")) |> -#' dplyr::filter(country_name == "Japan") |> -#' dplyr::slice_tail(n = 10) |> +#' dplyr::filter( +#' country_name == "Japan", +#' year %in% 2012:2021 +#' ) |> #' gt() |> #' cols_move( #' columns = population, @@ -214,8 +216,10 @@ cols_move <- function( #' ```r #' countrypops |> #' dplyr::select(-contains("code")) |> -#' dplyr::filter(country_name == "Fiji") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Fiji", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_move_to_start(columns = year) #' ``` @@ -231,8 +235,10 @@ cols_move <- function( #' ```r #' countrypops |> #' dplyr::select(-contains("code")) |> -#' dplyr::filter(country_name == "Fiji") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Fiji", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_move_to_start(columns = c(year, population)) #' ``` @@ -336,8 +342,10 @@ cols_move_to_start <- function( #' ```r #' countrypops |> #' dplyr::select(-contains("code")) |> -#' dplyr::filter(country_name == "Benin") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Benin", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_move_to_end(columns = year) #' ``` @@ -353,8 +361,10 @@ cols_move_to_start <- function( #' ```r #' countrypops |> #' dplyr::select(-contains("code")) |> -#' dplyr::filter(country_name == "Benin") |> -#' dplyr::slice_tail(n = 5) |> +#' dplyr::filter( +#' country_name == "Benin", +#' year %in% 2017:2021 +#' ) |> #' gt() |> #' cols_move_to_end(columns = c(year, country_name)) #' ``` diff --git a/R/data_color.R b/R/data_color.R index 06b3f68400..52c0c9aafb 100644 --- a/R/data_color.R +++ b/R/data_color.R @@ -439,9 +439,11 @@ #' #' ```r #' countrypops |> -#' dplyr::filter(country_name == "Bangladesh") |> #' dplyr::select(-contains("code")) |> -#' dplyr::slice_tail(n = 10) |> +#' dplyr::filter( +#' country_name == "Bangladesh", +#' year %in% 2012:2021 +#' ) |> #' gt() |> #' data_color( #' columns = population, @@ -464,9 +466,11 @@ #' #' ```r #' countrypops |> -#' dplyr::filter(country_name == "Bangladesh") |> #' dplyr::select(-contains("code")) |> -#' dplyr::slice_tail(n = 10) |> +#' dplyr::filter( +#' country_name == "Bangladesh", +#' year %in% 2012:2021 +#' ) |> #' gt() |> #' data_color( #' columns = population, diff --git a/R/format_data.R b/R/format_data.R index 74876865e6..01e7cf053b 100644 --- a/R/format_data.R +++ b/R/format_data.R @@ -8005,7 +8005,7 @@ get_image_hw_ratio <- function(filepath) { #' make this work seamlessly, the input cells need to contain some reference to #' a country, and this can be in the form of a 2- or 3-letter ISO 3166-1 country #' code (e.g., Egypt has the `"EG"` country code). This function will parse the -#' targeted body cells for those codes (and the [countrypops] dataset contains +#' targeted body cells for those codes (and the [`countrypops`] dataset contains #' all of them) and insert the appropriate flag graphics. #' #' Multiple flags can be included per cell by separating country codes with diff --git a/man/cols_align.Rd b/man/cols_align.Rd index 4e7537bf1e..24d32c7bb1 100644 --- a/man/cols_align.Rd +++ b/man/cols_align.Rd @@ -63,9 +63,14 @@ the label and body cells of \code{population} will be aligned to the left. \if{html}{\out{
}}\preformatted{countrypops |> dplyr::select(-contains("code")) |> - dplyr::filter(country_name == "San Marino") |> - dplyr::slice_tail(n = 5) |> - gt(rowname_col = "year", groupname_col = "country_name") |> + dplyr::filter( + country_name == "San Marino", + year \%in\% 2017:2021 + ) |> + gt( + rowname_col = "year", + groupname_col = "country_name" + ) |> cols_align( align = "left", columns = population diff --git a/man/cols_hide.Rd b/man/cols_hide.Rd index de9ff622dc..1adb916cd9 100644 --- a/man/cols_hide.Rd +++ b/man/cols_hide.Rd @@ -54,8 +54,10 @@ table. We can hide the \code{country_code_2} and \code{country_code_3} columns w \code{cols_hide()} function. \if{html}{\out{
}}\preformatted{countrypops |> - dplyr::filter(country_name == "Egypt") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Egypt", + year \%in\% 2017:2021 + ) |> gt() |> cols_hide(columns = c(country_code_2, country_code_3)) }\if{html}{\out{
}} @@ -71,8 +73,10 @@ that column along with the \code{country_code_3} column. Note that the order of table. \if{html}{\out{
}}\preformatted{countrypops |> - dplyr::filter(country_name == "Pakistan") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Pakistan", + year \%in\% 2017:2021 + ) |> gt() |> cols_hide(columns = c(country_code_3, population)) |> tab_footnote( diff --git a/man/cols_label.Rd b/man/cols_label.Rd index dd1485fde8..91c433770d 100644 --- a/man/cols_label.Rd +++ b/man/cols_label.Rd @@ -135,8 +135,10 @@ the column on the left-hand side, and the label text on the right-hand side. \if{html}{\out{
}}\preformatted{countrypops |> dplyr::select(-contains("code")) |> - dplyr::filter(country_name == "Uganda") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Uganda", + year \%in\% 2017:2021 + ) |> gt() |> cols_label( country_name = "Name", @@ -156,8 +158,10 @@ a \code{~} between the column name and the label text. \if{html}{\out{
}}\preformatted{countrypops |> dplyr::select(-contains("code")) |> - dplyr::filter(country_name == "Uganda") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Uganda", + year \%in\% 2017:2021 + ) |> gt() |> cols_label( country_name = md("**Name**"), diff --git a/man/cols_move.Rd b/man/cols_move.Rd index 1202af420f..c564482df2 100644 --- a/man/cols_move.Rd +++ b/man/cols_move.Rd @@ -65,8 +65,10 @@ position the \code{population} column after the \code{country_name} column by us \if{html}{\out{
}}\preformatted{countrypops |> dplyr::select(-contains("code")) |> - dplyr::filter(country_name == "Japan") |> - dplyr::slice_tail(n = 10) |> + dplyr::filter( + country_name == "Japan", + year \%in\% 2012:2021 + ) |> gt() |> cols_move( columns = population, diff --git a/man/cols_move_to_end.Rd b/man/cols_move_to_end.Rd index b9f53f0f9a..154992237f 100644 --- a/man/cols_move_to_end.Rd +++ b/man/cols_move_to_end.Rd @@ -50,8 +50,10 @@ middle column, to the end of the column series with \code{cols_move_to_end()}. \if{html}{\out{
}}\preformatted{countrypops |> dplyr::select(-contains("code")) |> - dplyr::filter(country_name == "Benin") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Benin", + year \%in\% 2017:2021 + ) |> gt() |> cols_move_to_end(columns = year) }\if{html}{\out{
}} @@ -66,8 +68,10 @@ columns to the end of the column series. \if{html}{\out{
}}\preformatted{countrypops |> dplyr::select(-contains("code")) |> - dplyr::filter(country_name == "Benin") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Benin", + year \%in\% 2017:2021 + ) |> gt() |> cols_move_to_end(columns = c(year, country_name)) }\if{html}{\out{
}} diff --git a/man/cols_move_to_start.Rd b/man/cols_move_to_start.Rd index 05106a6030..da93a65f19 100644 --- a/man/cols_move_to_start.Rd +++ b/man/cols_move_to_start.Rd @@ -51,8 +51,10 @@ middle column, to the start of the column series with \code{cols_move_to_start() \if{html}{\out{
}}\preformatted{countrypops |> dplyr::select(-contains("code")) |> - dplyr::filter(country_name == "Fiji") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Fiji", + year \%in\% 2017:2021 + ) |> gt() |> cols_move_to_start(columns = year) }\if{html}{\out{
}} @@ -67,8 +69,10 @@ columns to the start of the column series. \if{html}{\out{
}}\preformatted{countrypops |> dplyr::select(-contains("code")) |> - dplyr::filter(country_name == "Fiji") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Fiji", + year \%in\% 2017:2021 + ) |> gt() |> cols_move_to_start(columns = c(year, population)) }\if{html}{\out{
}} diff --git a/man/cols_unhide.Rd b/man/cols_unhide.Rd index 50a520f613..bf8a0aa973 100644 --- a/man/cols_unhide.Rd +++ b/man/cols_unhide.Rd @@ -49,8 +49,10 @@ table. We'll hide the \code{country_code_2} and \code{country_code_3} columns wi \if{html}{\out{
}}\preformatted{tab_1 <- countrypops |> - dplyr::filter(country_name == "Singapore") |> - dplyr::slice_tail(n = 5) |> + dplyr::filter( + country_name == "Singapore", + year \%in\% 2017:2021 + ) |> gt() |> cols_hide(columns = c(country_code_2, country_code_3)) diff --git a/man/data_color.Rd b/man/data_color.Rd index c6cd4aac79..96d1ba0d40 100644 --- a/man/data_color.Rd +++ b/man/data_color.Rd @@ -457,9 +457,11 @@ to the \code{population} column with the \code{"numeric"} method, use a domain b 2.5 and 3.4 million, and specify \code{palette = "viridis"}. \if{html}{\out{
}}\preformatted{countrypops |> - dplyr::filter(country_name == "Bangladesh") |> dplyr::select(-contains("code")) |> - dplyr::slice_tail(n = 10) |> + dplyr::filter( + country_name == "Bangladesh", + year \%in\% 2012:2021 + ) |> gt() |> data_color( columns = population, @@ -481,9 +483,11 @@ vector of numeric values and returns color values. Here is an alternate version of the code that returns the same table as in the previous example. \if{html}{\out{
}}\preformatted{countrypops |> - dplyr::filter(country_name == "Bangladesh") |> dplyr::select(-contains("code")) |> - dplyr::slice_tail(n = 10) |> + dplyr::filter( + country_name == "Bangladesh", + year \%in\% 2012:2021 + ) |> gt() |> data_color( columns = population, diff --git a/man/fmt_flag.Rd b/man/fmt_flag.Rd index 0f4f97aa7c..9a09a1639e 100644 --- a/man/fmt_flag.Rd +++ b/man/fmt_flag.Rd @@ -89,7 +89,7 @@ function helps with inserting a flag icon (or multiple) in body cells. To make this work seamlessly, the input cells need to contain some reference to a country, and this can be in the form of a 2- or 3-letter ISO 3166-1 country code (e.g., Egypt has the \code{"EG"} country code). This function will parse the -targeted body cells for those codes (and the \link{countrypops} dataset contains +targeted body cells for those codes (and the \code{\link{countrypops}} dataset contains all of them) and insert the appropriate flag graphics. Multiple flags can be included per cell by separating country codes with