Skip to content

Instantly share code, notes, and snippets.

View rich-iannone's full-sized avatar

Richard Iannone rich-iannone

View GitHub Profile
@rich-iannone
rich-iannone / gt_populations.R
Created April 6, 2023 18:31
Population Ranges
library(gt)
library(tidyverse)
countrypops |>
dplyr::filter(year == 2021) |>
dplyr::select(country_code_2, population) |>
dplyr::mutate(population_class = cut(
population,
breaks = scales::breaks_log(n = 20)(population)
)) |>
@rich-iannone
rich-iannone / new_gt_0.8.0.Rmd
Created December 2, 2022 17:38
This is the slightly revised R Markdown source of the Posit blog post at https://posit.co/blog/new-features-upgrades-in-gt-0-8-0/.
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(gt)
library(gtsummary)
library(tidyverse)
```
@rich-iannone
rich-iannone / gt-color-contrast-computation-comparison.R
Last active October 20, 2023 15:31
This gist generates a gt table that compares text color choices from the WCAG and APCA contrast methods. Implemented in the `data_color()` function of the gt package, where the background is set first (based on cell data) and the color of the overlaid text is determined from the color contrast algorithm.
library(gt)
library(tidyverse)
color_sequence <- seq_along(grDevices::colors())
dplyr::tibble(
x11c = grDevices::colors(),
wcag = color_sequence,
apca = color_sequence
) %>%
@rich-iannone
rich-iannone / news-orgs-early.R
Created April 5, 2022 16:46
An in-progress build of a gt table that uses the `2022-04-05/news_orgs.csv` TidyTuesday dataset
library(gt)
library(tidyverse)
# Table reading
news_orgs <-
readr::read_csv(
file = 'https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-04-05/news_orgs.csv',
col_types = cols(
publication_name = col_character(),
parent_publication = col_character(),
@rich-iannone
rich-iannone / gh_issue_labels.R
Last active March 4, 2021 16:32
GitHub Issue Labels
library(usethis)
labels <-
c(
"Blocked (╥﹏╥)",
"Difficulty: ③ Advanced",
"Difficulty: ② Intermediate",
"Difficulty: ① Novice",
"Effort: ③ High",
"Effort: ② Medium",
@rich-iannone
rich-iannone / information_palmerpenguins.R
Last active January 19, 2021 23:48
A pointblank information report for the `peguins` dataset in the `palmerpenguins` package
library(pointblank)
library(palmerpenguins)
informant_pp <-
create_informant(
read_fn = ~ palmerpenguins::penguins,
tbl_name = "penguins",
label = "The `penguins` dataset from the **palmerpenguins** 📦."
) %>%
info_columns(
@rich-iannone
rich-iannone / gtcars_rtf.R
Created October 5, 2020 18:40
An example of how to create a gt table and output an RTF file
library(gt)
library(tidyverse)
order_countries <- c("Germany", "Italy", "United States", "Japan")
best_gas_mileage_city <-
gtcars %>%
dplyr::arrange(desc(mpg_c)) %>%
dplyr::slice(1) %>%
dplyr::mutate(car = paste(mfr, model)) %>%
@rich-iannone
rich-iannone / tests_informant-revenue-postgres.R
Created October 1, 2020 23:11
A example of how to create an informant for the `revenue` table (hosted on a PostgreSQL DB)
library(pointblank)
library(here)
library(intendo)
# Note: while this table is hosted on a database, the table can be obtained
# from the {intendo} package (https://github.com/rich-iannone/intendo)
informant_revenue_postgres <-
create_informant(
read_fn =
@rich-iannone
rich-iannone / reencode_utf8.R
Created July 25, 2020 22:12
A function that reencodes UTF-8 characters to code points
reencode_utf8 <- function(x) {
# Ensure that we encode non-UTF-8 strings to UTF-8 in a
# two-step process: (1) to native encoding, and then
# (2) to UTF-8
if (Encoding(x) != 'UTF-8') {
x <- enc2utf8(x)
}
# Use `iconv()` to convert to UTF-32 (big endian) as
@rich-iannone
rich-iannone / gist:1da1ae7a7203958a0c5b1bd1d4b24017
Last active October 13, 2021 03:51
This gt code allows you to make a summary table based on the `pizzaplace` dataset.
library(tidyverse)
library(paletteer)
library(gt)
pizzaplace %>%
mutate(type = case_when(
type == "chicken" ~ "chicken (pizzas with chicken as a major ingredient)",
type == "classic" ~ "classic (classical pizzas)",
type == "supreme" ~ "supreme (pizzas that try a little harder)",
type == "veggie" ~ "veggie (pizzas without any meats whatsoever)",