Skip to content

Commit

Permalink
Merge pull request #1874 from rstudio/update-countrypops-dataset
Browse files Browse the repository at this point in the history
Update `countrypops` dataset
  • Loading branch information
rich-iannone authored Sep 4, 2024
2 parents 33e9d62 + 93d1180 commit 99dd5cb
Show file tree
Hide file tree
Showing 28 changed files with 350 additions and 288 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method("$",gt_option)
S3method(add_text_style,character)
S3method(add_text_style,shiny.tag)
S3method(as.data.frame,gt_tbl)
Expand Down
11 changes: 8 additions & 3 deletions R/cols_align.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions R/cols_hide.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
#' ```
Expand All @@ -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(
Expand Down Expand Up @@ -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))
#'
Expand Down
12 changes: 8 additions & 4 deletions R/cols_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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**"),
Expand Down
30 changes: 20 additions & 10 deletions R/cols_move.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
#' ```
Expand All @@ -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))
#' ```
Expand Down Expand Up @@ -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)
#' ```
Expand All @@ -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))
#' ```
Expand Down
12 changes: 8 additions & 4 deletions R/data_color.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions R/datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
#------------------------------------------------------------------------------#


#' Yearly populations of countries from 1960 to 2022
#' Yearly populations of countries from 1960 to 2023
#'
#' @description
#'
#' A dataset that presents yearly, total populations of countries. Total
#' population is based on counts of all residents regardless of legal status or
#' citizenship. Country identifiers include the English-language country names,
#' and the 2- and 3-letter ISO 3166-1 country codes. Each row contains a
#' `population` value for a given `year` (from 1960 to 2022). Any `NA` values
#' for `populations` indicate the non-existence of the entity during that year.
#' `population` value for a given `year` (from 1960 to 2023). Any `NA` values
#' within `population` indicate the non-existence of the entity during that
#' year.
#'
#' @format A tibble with 13,545 rows and 5 variables:
#' @format A tibble with 13,760 rows and 5 variables:
#' \describe{
#' \item{country_name}{The name of the country.}
#' \item{country_code_2, country_code_3}{The 2- and 3-letter ISO 3166-1 country
Expand Down
2 changes: 1 addition & 1 deletion R/format_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions data-raw/01-countrypops.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ countrypops <-
`2019` = col_integer(),
`2020` = col_integer(),
`2021` = col_integer(),
`2022` = col_integer()
`2022` = col_integer(),
`2023` = col_integer()
), na = character()
) %>%
tidyr::gather("year", "population", `1960`:`2022`) %>%
tidyr::gather("year", "population", `1960`:`2023`) %>%
dplyr::arrange(country_code_3, year) %>%
dplyr::mutate(year = as.integer(year))
Loading

0 comments on commit 99dd5cb

Please sign in to comment.