This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# library(tidyverse) | |
# library(tidytext) | |
##### Use the following function for reading a folder of prose text files. ##### | |
## Put all the text files you want to read in the same folder. If that folder's | |
## called, for example, "project2", here's the function in practice: | |
## | |
## my_table <- tidy_prose_texts(folder = "project2") | |
## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### stylo_log ##### | |
# Pipe from stylo() directly into stylo_log() | |
# or wrap stylo() in stylo_log() | |
# Examples: | |
# stylo() |> stylo_log() | |
# stylo_log(stylo()) | |
stylo_log <- function( | |
stylo_object, | |
log_label = NULL, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_if_needed <- function( | |
# Url to be downloaded, necessary | |
url, | |
# destination filename (optional) | |
filename = NULL, | |
# destination directory (optional) | |
destdir = "data" | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### Load libraries ##### | |
library(dplyr) | |
library(stringi) | |
library(stringr) | |
library(tidyr) | |
library(stringdist) | |
library(tokenizers) | |
##### Set up replicable workflow ##### | |
# Set the directories to be used. Both directories should exist in project directory, and dir_start should include text files needing to be processed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import_bib.R | |
# To convert from Bibtex to a data frame for working with the data in R. | |
library(dplyr) | |
library(stringr) | |
library(tidyr) | |
# 0. Set filename for the bibfile | |
the_bibfile <- "~/path/to/my.bib" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# make a pinwheel: first set up directions. The blades are drawn in different orders for clockwise and counterclockwise | |
clockwise_t <- c(2, 1, 3, 4) | |
clockwise_f <- c(4, 3, 1, 2) | |
direction <- list(clockwise_t, clockwise_f) | |
# create a 4-color pinwheel with 4 blades facing the same direction | |
get_pinwheel <- | |
function( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\usepackage{listings} | |
\usepackage{xcolor} | |
\let\oldaddbibresource\addbibresource | |
\renewcommand{\addbibresource}[1]{% | |
\oldaddbibresource{#1}% | |
\expandafter\newcommand\csname thebibfile\endcsname{#1}% | |
} | |
% \makeatletter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To prepare it for use in documentation, import a .bib file, strip Bibdesk's extra fields and additions, and enclose each entry with code compatible with Latex's {listings} package. | |
library(dplyr) | |
library(stringr) | |
library(readr) | |
# 0. Set relative file path for the bibfile | |
# setwd() | |
# 1. read the bib file as a vector of lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\newrobustcmd*{\mkcomprangezero}{% | |
\begingroup | |
\@ifstar | |
{\blx@range@aux\blx@comprange@ii} | |
{\blx@range@aux\blx@comprange@i}} | |
\def\blx@comprange@i[#1][#2]#3{% | |
\let\blx@tempa\@empty | |
\protected\def\blx@range@out@value{\appto\blx@tempa}% | |
\def\blx@range@out@item@process{#2}% | |
\let\blx@range@out@delim\blx@range@out@value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remotes::install_github("kjhealy/covdata") | |
library(covdata) | |
library(dplyr) | |
library(ggplot2) | |
library(ggrepel) | |
library(tidyr) | |
covus_wide <- covus %>% | |
select(date, state, measure, count) %>% | |
pivot_wider(id_cols = c(date, state), |