#' Gets stopwords from a default list and user-provided list
#'
#' @param lexicon a string name of a stopword list, one of "smart",
#' "snowball", or "onix"
#'
#' @param addl user defined character vector of additional stopwords,
#' each element being a stopword
#'
#' @return a [tibble][tibble::tibble-package] with one column named "word"
get_sw <- function(lexicon = "snowball", addl = NA){
addl_char <- as.character(addl)
tidytext::get_stopwords(source = lexicon) %>%
dplyr::select(word) %>%
dplyr::bind_rows(., tibble::tibble(word = addl_char)) %>%
stats::na.omit() %>%
purrr::as_vector() %>%
tolower() %>%
as.character()
}
#' determine stopword status
#'
#' @param .data vector of words
#'
#' @param ... arguments of get_sw
#'
#' @return a [tibble][tibble::tibble-package] equivalent to the input
#' dataframe, with an additional stopword column
#'
#' @export
determine_stopwords <- function(.data, ...){
sw_list <- get_sw(...)
.data %in% sw_list
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.