rtweettree_tbl_graph: Create a tidygraph tbl_graph object

Description Usage Arguments Value Methods (by class) Examples

View source: R/rtweettree_tbl_graph.R

Description

Create a 'tidygraph::tbl_graph' object representing the tree structure of a tweet and all replies, quotes and likes that could be scraped using rtweet.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
rtweettree_tbl_graph(x, add_profile_pics = TRUE, ...)

## S3 method for class 'rtweettree_data'
rtweettree_tbl_graph(x, add_profile_pics = TRUE, ...)

## S3 method for class 'rtweettree_tbl_graph'
rtweettree_tbl_graph(x, add_profile_pics = TRUE, ...)

## S3 method for class 'character'
rtweettree_tbl_graph(x, add_profile_pics = TRUE, ...)

Arguments

x

rtweet status_id or rtweettree_data object

add_profile_pics

logical whether to scrape the profile pictures of the twitter users and add them to the nodes tibble (if available); defaults to TRUE.

...

for the moment not used

Value

A tidygraph tbl_graph object representing the tree structure of all scraped subtweets of the tweet.

Methods (by class)

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
## Not run: 
main_status_id <- "1438481824922181635"
df_main_status <- rtweet::lookup_statuses(main_status_id)
df_tree <- search_tree(main_status_id)
tree_ids <- df_tree$user_id %>% unique()
df_tls <- scrape_timelines(tree_ids)
df0 <- df_main_status %>%
  dplyr::filter(status_id == main_status_id) %>%
  dplyr::select(to = status_id, user_id) %>%
  dplyr::mutate(from = "root", type = "root")
tweet_edges <-
  find_connections_rec(dplyr::bind_rows(df_tree, df_tls), df0)
ids <- tweet_edges$user_id %>% unique()
df_favs <- scrape_favs2(ids, main_status_id)
tweet_ids <- list(df_tls, df_favs, df_main_status) %>%
  dplyr::bind_rows() %>%
  pull(status_id) %>%
  unique()
df_retweets <- tweet_ids %>% purrr::map_dfr(~rtweet::get_retweets(.x))

rtweettree_data_scraped <- tibble::lst(df_main_status, df_tree, df_tls, df_favs, df_retweets)
g <- rtweettree_tbl_graph(rtweettree_data_scraped)
g %>% ggraph::ggraph() + ggraph::geom_node_point() + ggraph::geom_edge_link()

## End(Not run)
# With package example dataset included:
rtweettree_tbl_graph(rtweettree_data_example)

urswilke/rtweettree documentation built on Oct. 14, 2021, 6:32 p.m.