mark_sentences: Mark Words Containing Regex With Class for Highlighting

Description Usage Arguments Value See Also Examples

Description

mark_sentences - Mark sentences containing regex with a class for highlighting.

mark_sentences2 - Mark sentences predetemined class for highlighting.

Usage

1
2
3
mark_sentences(x, regex, marks_class, ignore.case = FALSE)

mark_sentences2(x, classes)

Arguments

x

A character vector with regex to operate on.

regex

The regex to search for.

marks_class

The classes to apply to word (must be equal to regex in length). These are dictated by the css generated for marks in highlight_template.

ignore.case

logical. If TRUE case is ignored.

classes

A predetermined vector of classes to apply to split_sentences(x).

Value

Returns a character vector with mark tags added around sentences that contain the regex.

Returns a character vector with mark tags added around predetermined sentences.

See Also

Other mark.functions: mark_regex, mark_word_stems, mark_words

Other mark.functions: mark_regex, mark_word_stems, mark_words

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
x <- c("I like good cheeses but she hated Bad cheese.  Do you?",
    "This is realy bad!", "I drank water.  I wanted juice but like it. Why not?")

## Example 1: Words
regex <- c("chees[^ ]*\\b", "like", "hate[^ ]*\\b", "good", "bad\\b")
marks_class <- c("neutral", "pos", "neg", "pos", "neg")
marks <- c(pos = "lightgreen", neg = "pink", neutral = "yellow")

(body <- mark_sentences(x, regex, marks_class))
## Not run: 
## To an external file
template2html(insert_body(highlight_template(marks), body))
open_html()

## End(Not run)

## Example 2: End Marks
regex <- c("\\.$", "\\?$", "\\!$")
marks_class <- c("statment", "question", "exclamation")
marks <- c(statment = "lightgreen", question = "pink", exclamation = "orange")

(body <- mark_sentences(x, regex, marks_class))
## Not run: 
## To an external file
template2html(insert_body(highlight_template(marks), body))
open_html()

## End(Not run)

## `mark_sentences2`: predetermined classes per sentence
x <- c("I like it.  Well I like it some.",  "You lie!",
    "I do?  I try not to.  I suppose sometimes...")

## `classes` must be this length
length(unlist(split_sentences(x)))

(body <- mark_sentences2(x, c("neg", "", "", "pos", "neutral", "")))
## Not run: 
## To an external file
marks <- c(pos = "lightgreen", neg = "pink", neutral = "yellow")
template2html(insert_body(highlight_template(marks), p(body)))
open_html()

## End(Not run)

trinker/hilight documentation built on May 31, 2019, 8:51 p.m.