Learn the basics of using the R programming language for text analysis
In this workshop you will learn about the basics of doing text analysis with the R programming language. This includes:
A basic understanding of the R programming language is recommended for this workshop.
Estimated workshop length: 2 hours
In preparation for this workshop, you will need to have a Posit account (previously was an R Studio Cloud account) and have a new R Studio project open on Posit Cloud. Follow the steps below to get set up.
install.packages("tidyverse")
install.packages("tokenizers")
library(tidyverse)
library(tokenizers)
Task Set #1
Create a variable called “text” using the following code:
text <- paste("You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings. I arrived here yesterday, and my first task is to assure my dear sister of my welfare and increasing confidence in the success of my undertaking")
Task Set #2
Task Set #3
Use the code below to load in the full text of the book “Frankenstein”
text <- paste(readLines("https://raw.githubusercontent.com/BrockDSL/R_for_Text_Analysis/master/frankenstein.txt"),collapse = "\n")
Use the code below to load in the word frequency dataset
wordfreq <- read_csv("https://raw.githubusercontent.com/BrockDSL/R_for_Text_Analysis/master/wordfrequency.csv")
Task Set 4
(optional) Try out the function on some of these other books using the code below to build the variables.
dracula_text <- paste(readLines("https://raw.githubusercontent.com/BrockDSL/R_for_Text_Analysis/master/dracula.txt"),collapse = "\n")
prideandprejudice_text <- paste(readLines("https://raw.githubusercontent.com/BrockDSL/R_for_Text_Analysis/master/prideandprejudice.txt"),collapse = "\n")
gatsby_text <- paste(readLines("https://raw.githubusercontent.com/BrockDSL/R_for_Text_Analysis/master/greatgatsby.txt"),collapse = "\n")
If you are looking to continue enhancing your knowledge of R, check out our other R workshops or try out one of the options below!
YaRrr! The Pirate’s Guide to R
Programming Historians R Text Analysis
This workshop is brought to you by the Brock University Digital Scholarship Lab. For a listing of our upcoming workshops go to Experience BU if you are a Brock affiliate or Eventbrite page for external attendees.