R/extract_hashtags.R

Defines functions extract_hashtags

Documented in extract_hashtags

#' Extracts all hashtags included in the input tweet data list
#'
#' @param tweets A vector of tweets
#'
#' @return Vector of hashtags
#' @export
#'
#' @examples
#' tweets <- c(
#'    "Make America Great Again #DonaldTrump"
#' )
#' extract_hashtags(tweets)
#'
extract_hashtags <- function(tweets) {
  if(!is.character(tweets)) {
    stop("input should be a character vector")
  }
  output_vec <- stringr::str_extract_all(tweets, "#\\S+")
  output_vec <-   stringr::str_remove_all(unlist(output_vec), "#")
  output_vec
}
UBC-MDS/textprepr documentation built on Feb. 5, 2022, 8:13 a.m.