Skip to content

Instantly share code, notes, and snippets.

Avatar

Hadley Wickham hadley

View GitHub Profile
View rstats-spam.R
library(rtweet)
library(tidyverse)
rt <- search_tweets("#rstats", n = 5000, include_rts = FALSE)
existing <- rtweet:::TWIT_get(NULL, "/1.1/mutes/users/ids", params = list(stringify_ids = TRUE))
danger_list <- c("Serverless", "IoT", "IIoT", "AI", "100DaysOfCode", "DEVCommunity", "FemTech")
spam <- rt %>%
View summary.md
library(tidyverse)

simple_data <- tibble(
  group = factor(rep(c("A", "B"), each = 15)),
  subject = 1:30,
  score = c(rnorm(15, 40, 20), rnorm(15, 60, 10))
)

simple_data_se <- simple_data %>% 
View arabic-ggplot2.R
library(ggplot2)
x <- c("بقرة", "دجاج", "حصان")
df <- data.frame(x = x, y = 1:3)
labels_rtl <- function(x) paste0("\u202B", x)
ggplot(df, aes(x, y)) +
geom_point() +
scale_x_discrete(labels = labels_rtl) +
View need-vs-if.R
# need + validate -----------------------------------------------------------
validate(
need(
mzfinder::check_mzr_object(ms_object$mzr_connection),
"Wasn't able to connect to MS file"
)
)
validate(
need(!is.null(input$ppm_input), "ppm_input must not be null"),
need(input$ppm_input > 0L, "ppm_input must be > 0")
View tidy-cocktails.R
# Code for quick exploration of
# https://github.com/rfordatascience/tidytuesday/tree/master/data/2020/2020-05-26
# Video at https://youtu.be/kHFmtKCI_F4
library(tidyverse)
cocktails <- readr::read_csv("boston_cocktails.csv")
# Are name and row_id equivalent? -----------------------------------------
View dplyr-1-quantile.R
library(dplyr, warn.conflicts = FALSE)
library(gapminder)
probs <- c(0.1, 0.5, 0.9)
gapminder %>%
group_by(continent) %>%
summarise(
probs = probs,
across(is.numeric & !year, ~ quantile(.x, probs))
)
View update-rstudio.sh
#!/bin/bash
#
# Installs the latest RStudio daily desktop build for OSX/macOS and Ubuntu(amd64)
#
# https://support.rstudio.com/hc/en-us/articles/203842428-Getting-the-newest-RStudio-builds
set -e
install_macos_daily() {
REDIRECT_URL="https://www.rstudio.org/download/latest/daily/desktop/mac/RStudio-latest.dmg"
echo "Discovering daily build from: ${REDIRECT_URL}"
# Perform a HEAD request to find the redirect target. We use the name of the
View dplyr-summarise.R
# What's the most natural way to express this code in base R?
library(dplyr, warn.conflicts = FALSE)
mtcars %>%
group_by(cyl) %>%
summarise(mean = mean(disp), n = n())
#> # A tibble: 3 x 3
#> cyl mean n
#> <dbl> <dbl> <int>
#> 1 4 105. 11
#> 2 6 183. 7
View github-commit-pattern.R
library(tidyverse)
library(gh)
library(lubridate)
library(glue)
repo <- tibble(json = unclass(gh("/user/repos", .limit = Inf)))
repo <- repo %>%
hoist(json,
owner = c("owner", "login"),
View tidyhancements-19.R
# =======================================
# = Enhancements to data tidying =
# = Hadley Wickham =
# = https://rstd.io/tidyhancements-2019 =
# =======================================
# What is tidy data? ----------------------------------------------------------
# 1. Each column is a variable.
# 2. Each row is an observation.
# 3. Each cell is a value.