bind_tweets | R Documentation |
This function binds information stored as JSON files. The experimental function convert_json
converts individual JSON files into either "raw" or "tidy" format.
bind_tweets(
data_path,
user = FALSE,
verbose = TRUE,
output_format = NA,
vars = c("text", "user", "tweet_metrics", "user_metrics", "hashtags", "ext_urls",
"mentions", "annotations", "context_annotations"),
quoted_variables = FALSE
)
convert_json(
data_file,
output_format = "tidy",
vars = c("text", "user", "tweet_metrics", "user_metrics", "hashtags", "ext_urls",
"mentions", "annotations", "context_annotations"),
quoted_variables = F
)
By default, bind_tweets
binds into a data frame containing tweets (from data_id.json files).
If users is TRUE, it binds into a data frame containing user information (from users_id.json).
For the "tidy" and "tidy2" format, parallel processing with furrr is supported. In order to enable parallel processing, workers need to be set manually through future::plan()
. See examples
Note that output of the tidy2 vars returns results of the Twitter API, rather than from tweet text. Therefore, certain variables, especially context annotations and quoted_variables, may not be present in older data.
a data.frame containing either tweets or user information
## Not run:
# bind json files in the directory "data" into a data frame containing tweets
bind_tweets(data_path = "data/")
# bind json files in the directory "data" into a data frame containing user information
bind_tweets(data_path = "data/", user = TRUE)
# bind json files in the directory "data" into a "tidy" data frame / tibble
bind_tweets(data_path = "data/", user = TRUE, output_format = "tidy")
# bind json files in the directory "data" into a "tidy2" data frame / tibble, get hashtags and
# URLs for both original and quoted tweets
bind_tweets(data_path = "data/", user = TRUE, output_format = "tidy2",
vars = c("hashtags", "ext_urls"),
quoted_variables = T)
# bind json files in the directory "data" into a "tidy2" data frame / tibble with parallel computing
## set up a multisession
future::plan("multisession")
## run the function - note that no additional arguments are required
bind_tweets(data_path = "data/", user = TRUE, output_format = "tidy2")
## Shut down parallel workers
future::plan("sequential")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.