Skip to content

Instantly share code, notes, and snippets.

Avatar

Jennifer (Jenny) Bryan jennybc

View GitHub Profile
@jennybc
jennybc / 2020-03-29_sane-legend.R
Created Mar 30, 2020
Make the legend order = data order, with forcats::fct_reorder2()
View 2020-03-29_sane-legend.R
library(tidyverse)
library(patchwork)
dat_wide <- tibble(
x = 1:3,
top = c(4.5, 4, 5.5),
middle = c(4, 4.75, 5),
bottom = c(3.5, 3.75, 4.5)
)
View TIOBE redux
Exerting my will over the gist name
@jennybc
jennybc / vv_transformer.R
Last active Aug 9, 2019
A glue transformer inspired by the "variables & values" f-string syntax in Python 3.8
View vv_transformer.R
library(glue)
vv_transformer <- function(text, envir) {
regex <- "=$"
if (!grepl(regex, text)) {
return(identity_transformer(text, envir))
}
text <- sub(regex, "", text)
res <- identity_transformer(text, envir)
n <- length(res)
@jennybc
jennybc / get-function-signatures_reprex.R
Last active Dec 26, 2019
List all function signatures in a package
View get-function-signatures_reprex.R
library(tidyverse)
## attach the package whose function signatures you want to examine
pkg <- "usethis"
library(pkg, character.only = TRUE)
x <- lsf.str(pos = paste0("package:", pkg))
## inspired by examining print.ls_str and head.function
get_signatures <- function(x) {
x %>%
View curl commands
curl 'https://sheets.googleapis.com/v4/spreadsheets/1eP_0mb67k0MD9BBEZ5gv7jsyFzcTvMbrr3uGTG1GXZk?includeGridData=true&ranges=Sheet1!A1%3AG6&key=AIzaSyDXicV6oK4vR948PUAvlyr7QhkNwCoQ0cA' -H 'Accept: application/json' --compressed > spreadsheets_get_3.json
curl 'https://sheets.googleapis.com/v4/spreadsheets/1eP_0mb67k0MD9BBEZ5gv7jsyFzcTvMbrr3uGTG1GXZk/values/Sheet1!A1%3AG6?key=AIzaSyDXicV6oK4vR948PUAvlyr7QhkNwCoQ0cA' -H 'Accept: application/json' --compressed > spreadsheets_values_get_3.json
View curl commands
curl 'https://sheets.googleapis.com/v4/spreadsheets/132Ij_8ggTKVLnLqCOM3ima6mV9F8rmY7HEcR-5hjWoQ?includeGridData=true&ranges=Sheet1!A1%3AF6&key=AIzaSyDXicV6oK4vR948PUAvlyr7QhkNwCoQ0cA' -H 'Accept: application/json' --compressed > spreadsheets_get_2.json
curl 'https://sheets.googleapis.com/v4/spreadsheets/132Ij_8ggTKVLnLqCOM3ima6mV9F8rmY7HEcR-5hjWoQ/values/Sheet1!A1%3AF6?key=AIzaSyDXicV6oK4vR948PUAvlyr7QhkNwCoQ0cA' -H 'Accept: application/json' --compressed > spreadsheets_values_get.json
View curl commands
curl 'https://sheets.googleapis.com/v4/spreadsheets/1BzfL0kZUz1TsI5zxJF1WNF01IxvC67FbOJUiiGMZ_mQ?includeGridData=true&ranges=Africa!A1%3AF3&key=AIzaSyDXicV6oK4vR948PUAvlyr7QhkNwCoQ0cA' -H 'Accept: application/json' --compressed > spreadsheets_get.json
curl 'https://sheets.googleapis.com/v4/spreadsheets/1BzfL0kZUz1TsI5zxJF1WNF01IxvC67FbOJUiiGMZ_mQ/values/Africa!A1%3AF3?key=AIzaSyDXicV6oK4vR948PUAvlyr7QhkNwCoQ0cA' -H 'Accept: application/json' --compressed > spreadsheets_values_get.json
View pmap-and-map2-also-useful.R
library(tidyverse)
## approximates big_df in the post
big_df <- mtcars %>%
select(cyl, mpg, disp) %>%
arrange(cyl) %>%
slice(17:22) %>%
rename(ID = cyl)
## dummy function that needs access to ID and data
@jennybc
jennybc / 2018-02_game-of-thrones-rectangling.R
Last active Apr 28, 2018
Live code that goes with Data Rectangling talk
View 2018-02_game-of-thrones-rectangling.R
#' ---
#' output:
#' word_document
#' ---
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
#+
library(repurrrsive)
library(tidyverse)
View day01.R
library(testthat)
rev_captcha <- function(x) {
x <- as.integer(strsplit(x, "")[[1]])
xd <- diff(c(x, x[1]))
sum(x[xd == 0])
}
expect_equal(rev_captcha("1122"), 3)
expect_equal(rev_captcha("1111"), 4)
You can’t perform that action at this time.