File: extractors.R

package info (click to toggle)
r-cran-rtweet 2.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,068 kB
  • sloc: sh: 13; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 1,048 bytes parent folder | download
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
28
29
30
#' Get tweets from users, or users from tweets
#'
#' Twitter API endpoints that return tweets also return data about the users who
#' tweeted, and most endpoints that return users also return their last tweet.
#' Showing these additional columns would clutter the default display, so
#' rtweet instead stores in special attributes and allows you to show them
#' with the `user_data()` and `tweets_data()` helpers.
#'
#' @return `user_data()` returns a data frame of users; `tweets_data()`
#'   returns a data frame of tweets.
#' @param tweets A data frame of tweets.
#' @export
users_data <- function(tweets) {
  users <- attr(tweets, "users", exact = TRUE)
  if (is.null(users)) {
    abort("`tweets` does not have a `users` attribute", call = current_call())
  }
  users
}

#' @param users A data frame of users.
#' @rdname users_data
#' @export
tweets_data <- function(users) {
  tweets <- attr(users, "tweets", exact = TRUE)
  if (is.null(tweets)) {
    abort("`users` does not have a `tweets` attribute", call = current_call())
  }
  tweets
}