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.

rtweettree_tbl_graph(x, add_profile_pics = TRUE, ...)

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

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

# S3 method for 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)

  • rtweettree_data: Construct rtweettree_tbl_graph object from rtweettree_data.

  • rtweettree_tbl_graph: return rtweettree_tbl_graph object as is.

  • character: First run rtweettree_data on the status id `x` and then transform to rtweettree tbl_graph.

Examples

if (FALSE) { 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() } # With package example dataset included: rtweettree_tbl_graph(rtweettree_data_example)
#> Joining, by = c("from", "to", "user_id", "screen_name", "type")
#> # A tbl_graph: 9 nodes and 18 edges #> # #> # A directed acyclic simple graph with 1 component #> # #> # Node Data: 9 × 6 (active) #> name type screen_name data text profile_pic #> <chr> <chr> <chr> <list> <chr> <list> #> 1 1438476950746636291 user rtweetbird1 <tibble [1 × 18]> NA <magck-mg> #> 2 1438480252003569671 user rtweetbird3 <tibble [1 × 18]> NA <magck-mg> #> 3 1438479415550390275 user rtweetbird2 <tibble [1 × 18]> NA <magck-mg> #> 4 1438481824922181635 tweet rtweetbird1 <tibble [1 × 90]> this is a… <magck-mg> #> 5 1438483457697591297 tweet rtweetbird3 <tibble [1 × 90]> @rtweetbi… <magck-mg> #> 6 1438482432030818307 tweet rtweetbird2 <tibble [1 × 90]> @rtweetbi… <magck-mg> #> # … with 3 more rows #> # #> # Edge Data: 18 × 5 #> from to user_id screen_name type #> <int> <int> <chr> <chr> <chr> #> 1 4 5 1438480252003569671 rtweetbird3 reply #> 2 4 6 1438479415550390275 rtweetbird2 reply #> 3 4 7 1438479415550390275 rtweetbird2 reply #> # … with 15 more rows