Skip to content

Instantly share code, notes, and snippets.

View jennybc's full-sized avatar

Jennifer (Jenny) Bryan jennybc

View GitHub Profile
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
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 April 28, 2018 12:20
Live code that goes with Data Rectangling talk
#' ---
#' output:
#' word_document
#' ---
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
#+
library(repurrrsive)
library(tidyverse)
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)
@jennybc
jennybc / lect08.R
Created November 8, 2017 16:49
lect08_prompts
library(tidyverse)
library(repurrrsive)
df <- tibble(
name = map_chr(got_chars, "name"),
titles = map(got_chars, "titles")
)
df
df <- got_chars %>% {
@jennybc
jennybc / noam.R
Last active June 26, 2019 15:20
Faking tidyr::drop_na(..., logic = "all")
library(tidyverse)
(df <- tibble(
x = c(1, NA, 3, NA),
y = c(1, NA, NA, 4),
z = 1:4
))
#> # A tibble: 4 × 3
#> x y z
#> <dbl> <dbl> <int>
#> 1 1 1 1
@jennybc
jennybc / alm.md
Created October 1, 2016 20:27
two words

Install and load alm

install_github("ropensci/alm")
library("alm")
@jennybc
jennybc / catfacts.R
Last active September 5, 2017 10:41
Goofing around with the catfacts API
httr::GET("http://catfacts-api.appspot.com/api/facts",
query = list(number = 5)) %>%
httr::content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON()
@jennybc
jennybc / broken.Rmd
Created September 2, 2016 20:51 — forked from gmbecker/broken.Rmd
DebuggingInRmd
We set up knitr so it doesn't catch errors, then set
`options(error=recover)` to set up R's debug-on-error machinery.
We have to do one additional thing, before the options call though:
trace the recover function with`sink(NULL)` to turn off the output
capturing so the R console is useful when the debugging framework
dumps us back into it. This has to happen before the options call
because that call grabs the `recover` object and stores it somewhere
so setting a trace on recover after the call won't affect the cached
version that gets called upon an error.
@jennybc
jennybc / 2016-05_summarise-all-test-drive.R
Created May 29, 2016 06:43
dplyr::summarise_all() and friends
#' ---
#' output: github_document
#' ---
#' Worth reminding that `summarise_*()` needs n-to-1 function, `mutate_*()`
#' needs n-to-n function?
#'
#' I can use variable selection helpers from `select()`. Yay! I just didn't
#' expect I would need to put them inside of `vars()`.
#'