Skip to content

Instantly share code, notes, and snippets.

View gadenbuie's full-sized avatar

Garrick Aden-Buie gadenbuie

View GitHub Profile
library(tidyverse)
checks <- cchecks::cch_pkgs_history(x = "xaringanthemer", limit = 50)
checks$data$history |>
unnest(checks) |>
filter(status != "OK") |>
mutate(across(date_updated, lubridate::ymd_hms)) |>
arrange(date_updated) |>
mutate(
@gadenbuie
gadenbuie / r-code-for-wide-months.R
Created August 16, 2022 03:19
From date to month to columns with a crosstab
library(tidyverse)
library(lubridate)
# https://data.cityofchicago.org/Public-Safety/Crimes-2015/vwwp-7yr9
crimes <- read_csv("crimes.csv", lazy = TRUE, show_col_types = FALSE)
crimes |>
slice_sample(n = 500) |>
mutate(
Date = mdy_hms(Date),
# These functions were borrowed from klmr/box
# https://github.com/klmr/box/tree/5e411d47/scripts
verify_function_has_value = function (file) {
rd = tools::parse_Rd(file)
type = find_tag(rd, 'docType')
(length(type) != 0L && type != 'function') || length(find_tag(rd, 'value')) != 0L
}
find_tag = function (rd, tag) {
library(dplyr)
library(dbplyr)
library(starwarsdb)
con <- starwars_connect()
tbl(con, sql("select * from films"))
#> # Source: SQL [?? x 6]
#> # Database: duckdb_connection
#> title episode_id opening_crawl director producer release_date
gist_to_carbon <- function(
gist_id,
file = "code.png",
bg = "#4A90E2",
bg_alpha = 1,
theme = "shades-of-purple",
font = "Fira+Code",
lang = "auto",
drop_shadow = TRUE,
width = 680,
library(dplyr)
library(tidyr)
library(purrr)
r_versions <- jsonlite::read_json("https://rversions.r-pkg.org/r-versions")
add_r_4_2 <- function(x) {
has_r_4_2 <- x %>%
filter(major == 4, minor == 2) %>%
nrow() %>%
version_diff <- function(old, new) {
stopifnot(length(old) == length(new))
if (length(old) > 1) {
has_names <- !is.null(names(old))
return(
mapply(version_diff, old, new, SIMPLIFY = FALSE, USE.NAMES = has_names)
)
}

Tidyverse all the way and read in the data from the gist

library(tidyverse)

gist_csv <- "https://gist.github.com/dgkeyes/e37a1aefba31578c29e1418b6f897a68/raw/9e15eec3e4d5f0c138f088510e5808ec68ef8320/all_content.csv"

x <- read_csv(gist_csv)
@gadenbuie
gadenbuie / user-prefs.json
Last active March 7, 2022 19:13
{rsprefs} RStudio Preferences Sync
{
"sync": {
"check_arguments_to_r_function_calls": true,
"check_unexpected_assignment_in_function_call": true,
"console_double_click_select": true,
"continue_comments_on_newline": true,
"document_author": "Luke Skywalker",
"editor_keybindings": "vim",
"font_size_points": 12,
"highlight_r_function_calls": true,
library(httr2)
# setup and perform the request for a file
req <- request("https://placekitten.com/200/300") %>%
req_perform()
# The response body contains raw data,
# so we read that into a vector (into memory so can't be super big)
resp_binary <- resp %>% resp_body_raw()