juliasilge / tidytext
1
#' Tidy dictionary objects from the quanteda package
2
#'
3
#' @importFrom generics tidy
4
#'
5
#' @param x A dictionary object
6
#' @param regex Whether to turn dictionary items from a glob to a regex
7
#' @param ... Extra arguments, not used
8
#'
9
#' @return A data frame with two columns: category and word.
10
#'
11
#' @name dictionary_tidiers
12
#'
13
#' @export
14
tidy.dictionary2 <- function(x, regex = FALSE, ...) {
15 1
  ret <- purrr::map_df(x, function(e) tibble(word = e),
16 1
                       .id = "category"
17
  ) %>%
18 1
    mutate(category = as.character(category))
19

20 1
  if (regex) {
21 0
    ret$word <- utils::glob2rx(ret$word)
22
  }
23 1
  ret
24
}

Read our documentation on viewing source code .

Loading