trinker / termco

Regular Expression Counts of Terms and Substrings
Other
25 stars 5 forks source link

as_term_list #32

Closed trinker closed 7 years ago

trinker commented 7 years ago

Easy way to turn vector of terms into term.list:

#' Title
#' 
#' Description
#' 
#' @param x
#' @param \ldots
#' @return
#' @references
#' @keywords
#' @export
#' @seealso
#' @examples 
#' \dontrun{
#' if (!require("pacman")) install.packages("pacman")
#' pacman::p_load(tidyverse)
#' 
#' bigrams <- ngram_collocations(x, n=10) %>%
#'     transmute(bigram = paste(term1, term2)) %>%
#'     unlist() %>%
#'     as_term_list() 
#' 
#' 
#' presidential_debates_2012 %>%
#'     with(term_count(dialogue, person, bigrams))
#' }
as_term_list <- function(x, ...){

    stopifnot(is.atomic(x))
    stats::setNames(as.list(x), gsub('\\s+', '_', x))
}