R/parse_twitter.R

Defines functions parse_twitter is_file parse_twitter.list parse_twitter.data.frame parse_twitter.stream_file parse_twitter.connection parse_twitter.character

parse_twitter <- function(.x) {
  UseMethod("parse_twitter")
}

is_file <- function(x) {
  is.character(x) && length(x) == 1 &&
    !grepl("\\n", x) && file.exists(x)
}

parse_twitter.list <- function(.x) {
  tweets_with_users(.x)
}

parse_twitter.data.frame <- function(.x) {
  .x <- list(.x)
  parse_twitter(.x)
}

parse_twitter.stream_file <- function(.x) {
  parse_stream(.x)
}

parse_twitter.connection <- function(.x) {
  .x <- summary(.x)$description
  parse_stream(.x)
}


parse_twitter.character <- function(.x) {
  if (is_file(.x)) {
    class(.x) <- c("stream_file", "character")
  } else if (length(.x) > 1) {
    .x <- paste0("[", .x, "]")
    .x <- .parse_stream_two(.x)
    return(.x)
  } else {
    .x <- parse_stream(.x)
    return(.x)
  }
  parse_twitter(.x)
}

Try the rtweet package in your browser

Any scripts or data that you put into this service are public.

rtweet documentation built on Jan. 11, 2020, 9:11 a.m.