search_tweets(q, n = 100, type = "mixed", max_id = NULL, parse = TRUE, token = NULL, ...)
type = "mixed"
, which is a mix between the other two
valid values type = "recent"
and type = "popular"
.parse = TRUE
saves users from the time
[and frustrations] associated with disentangling the Twitter
API return objects.token = NULL
fetches a non-exhausted token from
an environment variable tokens.make_url
.
All named arguments that do not match the above arguments
(i.e., count, type, etc.) will be built into the request.
To return only English language tweets, for example, use
lang = "en"
. Or, to exclude retweets, use
include_rts = FALSE
. For more options see Twitter's
API documentation.Number of tweets returned will often be less than what was specified by the user. This can happen because (a) the search query did not return many results (the search pool is already thinned out from the population of tweets to begin with) or (b) because you hit your rate limit for a given token. Even if the query has lots of hits and the rate limit should be able to max out at 18,000, the returned number of tweets may be lower, but that's only because the functions filter out duplicates (e.g., 18,000 tweets were actually returned, but 30 of them were removed because they were repeats).
## Not run:
# # search for 1000 tweets mentioning Hillary Clinton
# hrc <- search_tweets(q = "hillaryclinton", n = 1000)
#
# # data frame where each observation (row) is a different tweet
# hrc$tweets
#
# # data frame where each observation (row) is a different user
# hrc$users
#
# # search for 1000 tweets mentioning Donald Trump
# djt <- search_tweets(q = "realdonaldtrump", n = 1000)
# djt$tweets
# djt$users
# ## End(Not run)
Run the code above in your browser using DataLab