DSD_Transactions_TwitterStream: Twitter Stream transaction generator

Description Usage Arguments Details Value Author(s) References Examples

Description

A datastream generator that uses the streamR package to create transactions by sampling the twitter stream

Usage

1
2
3
4
5
6
7
8
9
DSD_Transactions_TwitterStream(consumer_key, consumer_secret, 
                                RegisteredOAuthCredentials = NULL, 
                                search_term = "", timeout = 10, language = "en",
                                parser = function(text) unique(
                                strsplit(
                                gsub(
                                "[^[:alnum:][:space:]#]", "", text), " ")[[1]]))
  
  

Arguments

consumer_key

The consumer key, provided by the twitter api

consumer_secret

The consumer secret key, also provided by the twitter api

RegisteredOAuthCredentials

Optional. The user can pass already registered twitter credentials using the ROAuth package. If the user does not pass this argument, it will attempt to register the twitter credentials using the consumer key and secret.

search_term

If the user specifies a search term, it will return only tweets that contain that term.

timeout

How long (in seconds) the data stream generator will sample the twitter stream when it runs out of stored tweets.

language

When a language code is specified, all of which can be found in the twitter API documentation, it will only return tweets in that language. The default is 'en', or english.

parser

The user can specify their own function for parsing tweets into individual words. The function must accept a string and return a list of strings. The default function removes punctuation except hashtags and splits the string by spaces.

Details

DSD_Transactions_TwitterStream creates a dsd that generates transactions from tweets sampled from the Twitter stream in real time, meaning unlike DSD_Transactions_Twitter, it receives a sampling of tweets that are happening right when the get_points() is called, rather than an archive of tweets from the last several hours or days

Value

Returns a DSD_Transactions_TwitterStream object (subclass of DSD_Transactions, DSD) which is a list of the defined params. The params are either passed in from the function or created internally

Author(s)

Derek Phanekham

References

https://dev.twitter.com/rest/public/search http://cran.r-project.org/web/packages/streamR/streamR.pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#create Twitter stream generator
## Not run: 
key <- "************************"
secret <- "**********************"

dsd <- DSD_Transactions_TwitterStream(consumer_key = key, consumer_secret = secret, search_term="#stream", timeout=10)

#create with already registered credentials

library(ROAuth)

cred <- ROAuth::OAuthFactory$new(consumerKey=key,
                         consumerSecret=secret,
                         requestURL='https://api.twitter.com/oauth/request_token',
                         accessURL='https://api.twitter.com/oauth/access_token',
                         authURL='https://api.twitter.com/oauth/authorize')
cred$handshake()
                         
dsd <- DSD_Transactions_TwitterStream(consumer_key = key, consumer_secret = secret, 
  RegisteredOAuthCredentials = cred, search_term="#stream", timeout=10)
                         

#get a transaction from the datastream
transaction <- get_points(dsd)

transaction


## End(Not run)

streamFPM documentation built on May 2, 2019, 4:45 p.m.