A r/Makefile => r/Makefile +11 -0
@@ 0,0 1,11 @@
+.PHONY: install
+install:
+ sudo pacman -S r-tidyr r-tidytext r-textdata
+ @echo "Interactively run R and call the following commands:"
+ @echo "> library(tidytext)"
+ @echo "> get_sentiments(\"afinn\")"
+
+.PHONY: run
+run:
+ Rscript main.r
+
A r/main.r => r/main.r +26 -0
@@ 0,0 1,26 @@
+#!/usr/bin/env Rscript
+
+library(tidytext) # for data, unnest_tokens
+data(stop_words)
+
+library(janeaustenr) # for austen_books
+
+library(dplyr) # for group_by, anti_join, inner_join, count, mutate
+
+library(tidyr) # for pivot_wider
+
+tidy_books <- austen_books() %>%
+ group_by(book) %>%
+ unnest_tokens(word, text) %>%
+ anti_join(stop_words)
+
+
+get_sentiments("afinn")
+
+sentiment <- tidy_books %>%
+ inner_join(get_sentiments("afinn")) %>%
+ summarise(sentiment = sum(value)) %>%
+ mutate(method = "AFINN")
+
+sentiment
+