streamR (version 0.4.4)

readTweets: Converts tweets in JSON format to R list.

Description

This function parses tweets downloaded using filterStream, sampleStream or userStream and returns a list.

Usage

readTweets(tweets, verbose = TRUE)

Arguments

tweets

A character string naming the file where tweets are stored or the name of the object in memory where the tweets were saved as strings.

verbose

logical, default is TRUE, which will print in the console the number of tweets that have been parsed.

Details

This function is the first step in the parseTweets function and is provided now as an independent function for convenience purposes. In cases where only one field is needed, it can be faster to extract it directly from the JSON data read in R as a list. It can also be useful to extract fields that are not parsed by parseTweets, such as hashtags or mentions.

The total number of tweets that are parsed might be lower than the number of lines in the file or object that contains the tweets because blank lines, deletion notices, and incomplete tweets are ignored.

See Also

parseTweets.

Examples

Run this code
# NOT RUN {
## The dataset example_tweets contains 10 public statuses published
## by @twitterapi in plain text format. The code below converts the object
## into a list and extracts only the text.

data(example_tweets)
tweets.list <- readTweets(example_tweets)
only.text <- unlist(lapply(tweets.list, '[[', 'text'))
## it can be done with an explicit loop:
only.text <- c()
for (i in 1:length(tweets.list)){
   only.text[i] <- tweets.list[[i]]['text']
}
print(unlist(only.text))



# }

Run the code above in your browser using DataCamp Workspace