Learn R Programming

polmineR (version 0.7.9)

highlight: Highlight tokens.

Description

Highlight tokens based on exact match, a regular expression or corpus position in kwic output or html document.

Usage

highlight(.Object, ...)

# S4 method for character highlight(.Object, highlight = list())

# S4 method for html highlight(.Object, highlight = list())

# S4 method for kwic highlight(.Object, highlight = list(), regex = FALSE, perl = TRUE, verbose = TRUE)

Arguments

.Object

a html or character object with html, or a kwic object

...

further parameters (unused)

highlight

a "list" of character or integer vectors, the names need to provide the colors, the values of the vector the term to be matched or a corpus position

regex

logical, whether character vectors give regular expressions

perl

logical, whether to use perl-style regular expressions for highlighting when regex is TRUE

verbose

logical, whether to output verbose messages

Examples

Run this code
# NOT RUN {
use("polmineR")
P <- partition("REUTERS", places = "argentina")
H <- html(P)
Y <- highlight(H, list(lightgreen = "higher"))
if (interactive()) htmltools::html_print(Y)

# highlight matches for a CQP query
H2 <- highlight(
  H,
  highlight = list(yellow = cpos(hits(P, query = '"prod.*"', cqp = TRUE)))
)

# the method can be used in pipe
if (require("magrittr")){
  P %>% html() %>% highlight(list(lightgreen = "1986")) -> H
  P %>% html() %>% highlight(list(lightgreen = c("1986", "higher"))) -> H
  P %>% html() %>% highlight(list(lightgreen = 4020:4023)) -> H
}

# use highlight for kwic output
K <- kwic("REUTERS", query = "barrel")
K2 <- highlight(K, highlight = list(yellow = c("oil", "price")))
if (interactive()) K2
# }

Run the code above in your browser using DataLab