This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| unnest_without_caps <- function( | |
| df, | |
| column = "text") { | |
| full <- df |> | |
| tidytext::unnest_tokens(word, {{column}}, to_lower = FALSE) | |
| big <- full |> | |
| dplyr::filter(str_detect(word, "^[A-Z]")) |> | |
| dplyr::pull(word) |
This file contains hidden or 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(wordcloud) | |
| library(topicmodels) | |
| library(plotly) | |
| # Moves a table of texts through the necessary | |
| # steps of preparation before building a topic | |
| # model. The function applies these steps: | |
| # 1. identifies text divisions by the `doc_id` | |
| # column | |
| # 2. divides each of the texts into same-sized |
This file contains hidden or 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
| --- | |
| title: "Importing SAS data into R" | |
| --- | |
| ## Get the data | |
| ```{r} | |
| # Just download it once | |
| if(!file.exists("medical.sas7bdat")) { | |
| download.file("http://www.principlesofeconometrics.com/sas/medical.sas7bdat", |
This file contains hidden or 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
| --- | |
| title: "Mapping with R" | |
| output: | |
| html_document: | |
| df_print: paged | |
| toc: true | |
| toc_float: true | |
| date: "2023-06-30" | |
| --- |