R/utils.R

Defines functions extract_tags check_start

extract_tags <- function(x){
  x <- stringr::str_match_all(x, "<START(.*?)>(.*?)<END>")[[1]]
  x <- tibble::as.tibble(x)
  names(x) <- c("string", "type", "name")

  # clean
  x$name <- trimws(as.character(x$name))
  x$name <- gsub("[[:punct:]]", "", x$name)

  # clean type
  x$type <- gsub(":", "", x$type)
  x
}

check_start <- function(x){
  pat <- "[[:punct:]]<START(.*?)|<START(.*?)>[[:punct:]]"
  l <- stringr::str_locate_all(x, pat)
}
news-r/decipher documentation built on July 19, 2019, 5:58 p.m.