knitr::opts_chunk$set( collapse = TRUE, warning = FALSE, comment = "#>", fig.path = "README-" ) library(readr)
hashtag is a compilation of commands from different twitter and sentiment analysis packages that help you do simple twitter scrapes and analyses - fast.
So far, only "afinn" sentiment analysis is available, which classifies words as 'positive' or 'negative' with an appropriate score. Give it a try!
Note, the user must set up their own twitter API connection. I found this site helpful: rStatistics.net
devtools::install_github("sk6aus6/hashtag")
library(hashtag) library(readr) library(twitteR)
First connect to Twitter. I store my twitter API keys in a file buried deep in my computer:
keys <- read_csv('/Users/yam/OneDrive/shared files/Statslearningcourse/twitteR/keys.csv') # setup_twitter_oauth(consumerKey, consumerSecret, accessToken, accessTokenSecret) setup_twitter_oauth(keys$key[1], keys$key[2], keys$key[3], keys$key[4])
Then write a regular expression you want to search twitter for, and use this as an input for hash_sentiment()
hash_sentiment(regex = "coriander|cilantro", num.tweets = 800, method = "afinn", sentiment = "positive", num.summary = 3, scrape = TRUE)
If you want to look at different parts of the same twitter scrape, set scrape = FALSE
hash_sentiment(regex = "coriander|cilantro", num.tweets = 800, method = "afinn", sentiment = "negative", num.summary = 6, scrape = FALSE)
Please excuse the swearing!!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.