Learn R Programming

rtweet (version 0.6.9)

search_users: Get users data on accounts identified via search query.

Description

Returns data for up to 1,000 users matched by user provided search query.

Usage

search_users(q, n = 100, parse = TRUE, token = NULL,
  verbose = TRUE)

Arguments

q

Query to be searched, used in filtering relevant tweets to return from Twitter's REST API. Should be a character string not to exceed 500 characters maximum. Spaces are assumed to function like boolean "AND" operators. To search for tweets including one of multiple possible terms, separate search terms with spaces and the word "OR". For example, the search query = "data science" searches for tweets using both "data" and "science" though the words can appear anywhere and in any order in the tweet. However, when OR is added between search terms, query = "data OR science", Twitter's REST API should return any tweet that includes either "data" or "science" appearing in the tweets. At this time, Twitter's users/search API does not allow complex searches or queries targeting exact phrases as is allowed by search_tweets.

n

Numeric, specifying the total number of desired users to return. Defaults to 100. Maximum number of users returned from a single search is 1,000.

parse

Logical, indicating whether to return parsed (data.frames) or nested list object. By default, parse = TRUE saves users from the time [and frustrations] associated with disentangling the Twitter API return objects.

token

Every user should have their own Oauth (Twitter API) token. By default token = NULL this function looks for the path to a saved Twitter token via environment variables (which is what `create_token()` sets up by default during initial token creation). For instruction on how to create a Twitter token see the tokens vignette, i.e., `vignettes("auth", "rtweet")` or see ?tokens.

verbose

Logical, indicating whether or not to output processing/retrieval messages.

Value

Data frame of users returned by query.

See Also

https://dev.twitter.com/overview/documentation

Other users: as_screenname, lists_subscribers, lookup_users, tweets_with_users, users_data

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
## search for up to 1000 users using the keyword rstats
rstats <- search_users(q = "rstats", n = 1000)

## data frame where each observation (row) is a different user
rstats

## tweets data also retrieved. can access it via tweets_data()
tweets_data(rstats)

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab