File: methods.R

package info (click to toggle)
r-cran-rtweet 1.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,224 kB
  • sloc: sh: 13; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,107 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# rbind ####
#' @export
rbind.tweets <- function(..., deparse.level = 1) {
  if (...length() == 1) return(..1)
  rt <- list(...)

  ud <- lapply(rt, users_data)
  udm <- do.call(rbind, ud)
  rt <- do.call(rbind.data.frame, rt)
  rt <- tibble::as_tibble(rt)
  attr(rt, "users") <- tibble::as_tibble(udm)
  class(rt) <- c("tweets", class(rt))
  rt
}

#' @export
rbind.users <- function(..., deparse.level = 1) {
  if (...length() == 1) return(..1)
  rt <- list(...)

  td <- lapply(rt, tweets_data)
  tdm <- do.call(rbind, td)
  rt <- do.call(rbind.data.frame, rt)
  rt <- tibble::as_tibble(rt)
  attr(rt, "tweets") <- tibble::as_tibble(tdm)
  class(rt) <- c("users", class(rt))
  rt
}


# subset ####
#' @export
`[.tweets` <- function(x, i, j, ..., drop) {
  tweets <- NextMethod()
  keep_users <- missing(drop) || !drop
  if (keep_users) {
    attr(tweets, "users") <- users_data(x)[i, ]
  }
  tweets
}

#' @export
`[.users` <- function(x, i, j, ..., drop) {
  users <- NextMethod()
  keep_tweets <- missing(drop) || !drop
  if (keep_tweets) {
    attr(users, "tweets") <- tweets_data(x)[i, ]
  }
  users
}