Skip to content

Instantly share code, notes, and snippets.

View JosiahParry's full-sized avatar
💻
on the 'puter

Josiah Parry JosiahParry

💻
on the 'puter
View GitHub Profile
@JosiahParry
JosiahParry / gdoc_to_rmd.R
Created October 26, 2019 23:35
Convert a Google Doc to an R Markdown Doc
library(googledrive)
# authenticate yourself
drive_auth()
gdoc_to_rmd <- function(drive_id, output, verbose = TRUE, overwrite = FALSE) {
# get the doc
doc <- drive_get(as_id(drive_id))
# set argument values by name
d <- rnorm(302, mean = 43.3, sd = 9.1)
# set them by position
i <- rnorm(212, 44.6, 9.2)
r <- rnorm(278, 45.1, 9.2)
# note that you do not need to put these functions inside of the c() function
# because they are already returning vectors.
# we use c now because we want to combine multiple vectors into one
@JosiahParry
JosiahParry / haven_purr_spss.R
Created November 30, 2019 15:22
Useful quick tricks I learned to deal with the hell that is SPSS .sav data format
# read in sav file
noise <- haven::read_sav("http://staff.bath.ac.uk/pssiw/stats2/noisedata.sav")
# convert coded response to response text
haven::as_factor(noise)
# read in sav file with column labels
personality <- haven::read_sav("http://staff.bath.ac.uk/pssiw/stats2/personality.sav")
# generate a get_label f(x) via purr
@JosiahParry
JosiahParry / labels_to_colnames.R
Last active November 30, 2019 17:46
The SPSS hellscape adds questions as the column label. I want these as the col header
label_to_colname <- function(df, pattern) {
get_label <- purrr::attr_getter("label")
col_labels <- purrr::map(df, get_label)
col_labels[unlist(map(col_labels, is.null))] <- names(col_labels[unlist(purrr::map(col_labels, is.null))])
if (missing(pattern)) {
names_to_replace <- rep(TRUE, ncol(df))
} else {
names_to_replace <- stringr::str_detect(names(col_labels), pattern)
@JosiahParry
JosiahParry / theme_bari.R
Created December 26, 2019 19:10
ggplot2 theme based on BARI website.
theme_bari <- function() {
theme_minimal() +
theme(
panel.grid.major.y = element_line(
size = .75
),
panel.grid = element_line(),
panel.border = element_rect(size = .5, fill = NA, color = "#524d4d"),
text = element_text(family = "HelveticaNeue-CondensedBold"),
@JosiahParry
JosiahParry / theme_bari.R
Last active February 11, 2021 19:48
ggplot2 theme based on BARI website.
theme_bari <- function() {
theme_minimal() +
theme(
panel.grid.major.y = element_line(
size = .75
),
panel.grid = element_line(),
panel.border = element_rect(size = .5, fill = NA, color = "#524d4d"),
text = element_text(family = "Arial Bold"),
plot.title = element_text(color = "#c00000", size = 24),
library(bbcharts)
library(tidyverse)
rock <- decade_end_bb("hot-rock-songs")
real_rock <- c("The Black Keys", "Panic! At The Disco", "Foo Fighters", "Fall Out Boy")
count(rock, artist, sort = TRUE) %>%
filter(n >= 2) %>%
mutate(artist = fct_reorder(artist, n),
library(bbcharts)
library(tidyverse)
rock <- decade_end_bb("hot-rock-songs")
real_rock <- c("The Black Keys", "Panic! At The Disco", "Foo Fighters", "Fall Out Boy")
count(rock, artist, sort = TRUE) %>%
filter(n >= 2) %>%
mutate(artist = fct_reorder(artist, n),
library(tidyverse)
#remotes::install_github("GuangchuangYu/nCov2019")
cases <- nCov2019::load_nCov2019(lang = "en")
pluck(cases, "global") %>%
group_by(time) %>%
summarise(cases = sum(cum_confirm)) %>%
---
title: "colorpalette.cinema"
output: html_document
---
Fetch the color palettes from [colorpalette.cinema](https://www.instagram.com/colorpalette.cinema/).
```{r include=FALSE}
library(wesanderson)
library(tidyverse)