Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added documentation headers

commit 08a269765a6b185d5f3dd522c876043ba9628715 1 parent 73cd671
Jeffrey Breen authored
Showing with 32 additions and 2 deletions.
  1. +8 −1 R/0_start.R
  2. +5 −0 R/1_load.R
  3. +7 −0 R/scrape.R
  4. +12 −1 R/sentiment.R
View
9 R/0_start.R
@@ -1,4 +1,11 @@
-# assume's we started R in the project's home directory
+#
+# 0_start.R - set environment variables specifying path locations,
+# load prerequistive libraries and our
+# score.sentiment() function from sentiment.R
+#
+
+
+# assumes we started R in the project's home directory
# or used setwd() to get there:
projectDir = getwd()
View
5 R/1_load.R
@@ -1,3 +1,8 @@
+#
+# 1_load.R - loads Twitter data, Hu & Liu's opinion lexicon, and the ACSI scores from disk
+#
+# scrape.R should be run once to collect and cache tweets before running this script.
+#
if (!file.exists(file.path(dataDir, 'american.tweets.RData' )) )
{
View
7 R/scrape.R
@@ -1,3 +1,10 @@
+#
+# scrape.R - scrape web data and cache to the data/ directory:
+#
+# * airline-related tweets via twitteR's searchTwitter()
+# * ACSI scores with XML's readHTMLTable()
+#
+
if (VERBOSE)
print("Searching Twitter for airline tweets and saving to disk")
View
13 R/sentiment.R
@@ -1,4 +1,15 @@
-
+#'
+#' score.sentiment() implements a very simple algorithm to estimate
+#' sentiment, assigning a integer score by subtracting the number
+#' of occurrences of negative words from that of positive words.
+#'
+#' @param sentences vector of text to score
+#' @param pos.words vector of words of postive sentiment
+#' @param neg.words vector of words of negative sentiment
+#' @param .progress passed to <code>laply()</code> to control of progress bar.
+#' @returnType data.frame
+#' @return data.frame of text and corresponding sentiment scores
+#' @author Jefrey Breen <jbreen@cambridge.aero>
score.sentiment = function(sentences, pos.words, neg.words, .progress='none')
{
require(plyr)
Please sign in to comment.
Something went wrong with that request. Please try again.