Skip to content

Instantly share code, notes, and snippets.

View gadenbuie's full-sized avatar

Garrick Aden-Buie gadenbuie

View GitHub Profile
@gadenbuie
gadenbuie / app.R
Last active January 24, 2020 15:06 — forked from MayaGans/app.R
library(shiny)
# dummy list of dataframes
test <- data.frame("A" = NA, "B" = NA, "X" = NA)
test2 <- data.frame("D" = NA, "E" = NA, "F" = NA)
test3 <- data.frame("G" = NA, "H" = NA, "X" = NA)
combined_tests <- list(test = test, test2 = test2, test3 = test3)
# Turn list of dataframes into buckets of draggable blocks
rowBlock <- function(name) {
@gadenbuie
gadenbuie / .Rprofile
Created February 3, 2020 18:11
current project and branch in R command prompt
if (interactive()) {
# requires: devtools::install_github("gaborcsardi/prompt")
.prompt_grk <- function(...) {
dir <- if (rstudioapi::hasFun("getActiveProject") &&
!is.null(rstudioapi::getActiveProject())) {
basename(rstudioapi::getActiveProject())
} else {
basename(getwd())
}
library(tidyverse)
f <- function(df, col) {
df %>%
summarize_at(col, list(col_mean = mean)) %>%
mutate(col = col) %>%
select(col, col_mean)
}
selected_cols <- c("mpg", "hp", "wt")
@gadenbuie
gadenbuie / walk_source.R
Last active February 21, 2020 17:40
Walk an R source file and run each command in RStudio automatically on a delay
walk_source <- function(
file = NULL,
delay = 1.5,
clear_each_cmd = TRUE,
style = styler::tidyverse_style
) {
options("walk_source_cancel" = FALSE)
if (is.null(file)) {
txt <- rstudioapi::getSourceEditorContext()$contents
} else {
@gadenbuie
gadenbuie / ggtext-reprex.md
Last active February 21, 2020 18:16
A ggtext reprex that led me down a few rabbit holes and ultimately solved several problems I didn't know I had...

It seems that left-positioned strip labels aren’t rendering as markdown. I’ve tested with both ggplot2@master and using [email protected] (shown here). Using the example from #2 where the issue with facet labels was first mentioned

library(dplyr)
library(glue)
library(ggtext)
library(ggplot2)
@gadenbuie
gadenbuie / output-classes.Rmd
Last active February 26, 2020 19:00
styled code output in xaringan slides
---
output:
xaringan::moon_reader:
lib_dir: libs
chakra: "https://cdnjs.cloudflare.com/ajax/libs/remark/0.14.0/remark.min.js"
seal: false
nature:
slideNumberFormat: ""
highlightStyle: github
ratio: "16:9"
---
title: Move <script> outside markdown area
output:
xaringan::moon_reader:
seal: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE)
```
library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
## This script was used to set up this project
# Install required packages (both for the book and this setup)
install.packages(c("tidyverse", "nycflights13", "gapminder", "Lahman", "remotes", "git2r", "here"))
# needed for converting the Rmd to R scripts
remotes::install_github("tjmahr/WrapRmd")
git2r::clone("https://github.com/hadley/r4ds.git", "r4ds-book")
fs::dir_create("r4ds-scripts")
library(tidyverse)
line_list <- read_csv("https://raw.githubusercontent.com/gadenbuie/covid19-florida/master/data/covid-19-florida_arcgis_line-list.csv")
summary <- read_csv("https://raw.githubusercontent.com/gadenbuie/covid19-florida/master/data/covid-19-florida_arcgis_summary.csv", guess_max = 1e5)

line_list %>% 
  group_by(event_date) %>%