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

More simplification of code + add missing pipes #1945

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 2 additions & 5 deletions R/cols_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@
#' name, ends_with("2001"), ends_with("2006"), matches("2001_2006")
#' ) |>
#' dplyr::filter(population_2001 > 100000) |>
#' dplyr::arrange(desc(pop_change_2001_2006_pct)) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_max(pop_change_2001_2006_pct, n = 10) |>
#' gt() |>
#' fmt_integer() |>
#' fmt_percent(columns = matches("change"), decimals = 1) |>
Expand All @@ -254,9 +253,7 @@
#' dplyr::select(
#' name, population_2021, density_2021, land_area_km2, latitude, longitude
#' ) |>
#' dplyr::filter(population_2021 > 100000) |>
#' dplyr::arrange(desc(population_2021)) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_max(population_2021, n = 10) |>
#' gt() |>
#' fmt_integer(columns = population_2021) |>
#' fmt_number(
Expand Down
2 changes: 1 addition & 1 deletion R/fmt_number.R
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ fmt_number <- function(
#' dplyr::select(country_code_3, year, population) |>
#' dplyr::filter(country_code_3 %in% c("CHN", "IND", "USA", "PAK", "IDN")) |>
#' dplyr::filter(year > 1975 & year %% 5 == 0) |>
#' tidyr::pivot_wider(names_from = year, values_from = population)
#' tidyr::pivot_wider(names_from = year, values_from = population) |>
#' dplyr::arrange(desc(`2015`)) |>
#' gt(rowname_col = "country_code_3") |>
#' fmt_integer(scale_by = 1 / 1E6) |>
Expand Down
14 changes: 5 additions & 9 deletions R/format_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -6193,9 +6193,8 @@ format_units_by_context <- function(
#' ```r
#' towny |>
#' dplyr::filter(csd_type == "city") |>
#' dplyr::arrange(desc(population_2021)) |>
#' dplyr::select(name, website, population_2021) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_max(population_2021, n = 10) |>
#' gt() |>
#' tab_header(
#' title = md("The 10 Largest Municipalities in `towny`"),
Expand Down Expand Up @@ -6223,9 +6222,8 @@ format_units_by_context <- function(
#' ```r
#' towny |>
#' dplyr::filter(csd_type == "city") |>
#' dplyr::arrange(desc(population_2021)) |>
#' dplyr::select(name, website, population_2021) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_max(population_2021, n = 10) |>
#' gt() |>
#' tab_header(
#' title = md("The 10 Largest Municipalities in `towny`"),
Expand Down Expand Up @@ -6261,9 +6259,8 @@ format_units_by_context <- function(
#' ```r
#' towny |>
#' dplyr::filter(csd_type == "city") |>
#' dplyr::arrange(desc(population_2021)) |>
#' dplyr::select(name, website, population_2021) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_max(population_2021, n = 10) |>
#' dplyr::mutate(ranking = dplyr::row_number()) |>
#' gt(rowname_col = "ranking") |>
#' tab_header(
Expand Down Expand Up @@ -6302,9 +6299,8 @@ format_units_by_context <- function(
#'
#' ```r
#' towny |>
#' dplyr::arrange(population_2021) |>
#' dplyr::select(name, website, population_2021) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_min(population_2021, n = 10) |>
#' gt() |>
#' tab_header(
#' title = md("The 10 Smallest Municipalities in `towny`"),
Expand Down Expand Up @@ -10017,7 +10013,7 @@ fmt_passthrough <- function(
#' dplyr::select(country_code_3, year, population) |>
#' dplyr::filter(country_code_3 %in% c("CHN", "IND", "USA", "PAK", "IDN")) |>
#' dplyr::filter(year > 1975 & year %% 5 == 0) |>
#' tidyr::pivot_wider(names_from = year, values_from = population)
#' tidyr::pivot_wider(names_from = year, values_from = population) |>
#' dplyr::arrange(desc(`2020`)) |>
#' gt(rowname_col = "country_code_3") |>
#' fmt_auto(lg_num_pref = "suf")
Expand Down
3 changes: 1 addition & 2 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,7 @@ currency <- function(
#'
#' ```r
#' towny |>
#' dplyr::arrange(desc(density_2021)) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_max(density_2021, n = 10) |>
#' dplyr::select(name, population_2021, density_2021, land_area_km2) |>
#' gt(rowname_col = "name") |>
#' fmt_integer(columns = population_2021) |>
Expand Down
3 changes: 1 addition & 2 deletions R/tab_footnote.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@
#' ```r
#' towny |>
#' dplyr::filter(csd_type == "city") |>
#' dplyr::arrange(desc(population_2021)) |>
#' dplyr::select(name, density_2021, population_2021) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_max(population_2021, n = 10) |>
#' gt(rowname_col = "name") |>
#' tab_header(
#' title = md("The 10 Largest Municipalities in `towny`"),
Expand Down
3 changes: 1 addition & 2 deletions R/text_transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ text_replace <- function(
#'
#' ```r
#' metro |>
#' dplyr::arrange(desc(passengers)) |>
#' dplyr::select(name, lines, connect_rer) |>
#' dplyr::slice_head(n = 10) |>
#' dplyr::slice_max(passengers, n = 10) |>
#' gt() |>
#' text_case_when(
#' stringr::str_count(x, pattern = "[ABCDE]") == 1 ~ "One connection.",
Expand Down
7 changes: 2 additions & 5 deletions man/cols_label.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fmt_auto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fmt_integer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions man/fmt_url.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/tab_footnote.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/text_case_when.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/unit_conversion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions vignettes/case-study-gtcars.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,15 @@ In terms of structuring the code, we're taking all the previous statements and p
# this will be used to target the correct cell for a footnote
best_gas_mileage_city <-
gtcars |>
arrange(desc(mpg_c)) |>
slice(1) |>
slice_max(mpg_c, n = 1) |>
mutate(car = paste(mfr, model)) |>
pull(car)

# Use dplyr functions to get the car with the highest horsepower
# this will be used to target the correct cell for a footnote
highest_horsepower <-
gtcars |>
arrange(desc(hp)) |>
slice(1) |>
slice_max(hp, n = 1) |>
mutate(car = paste(mfr, model)) |>
pull(car)

Expand Down
6 changes: 2 additions & 4 deletions vignettes/gt.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ islands_tbl <-
name = names(islands),
size = islands
) |>
arrange(desc(size)) |>
slice(1:10)
slice_max(size, n = 10)

# Display the table
islands_tbl
Expand Down Expand Up @@ -147,8 +146,7 @@ Here is a slightly more complex example of adding footnotes that use expressions
# largest landmass ('Asia')
largest <-
islands_tbl |>
arrange(desc(size)) |>
slice(1) |>
slice_max(size, n = 1) |>
pull(name)

# Create two additional footnotes, using the
Expand Down
Loading