| highlight {sentimentr} | R Documentation |
Highlight sentences within elements (row IDs) by sentiment polarity (positive = green; negative = pink) as an html file.
highlight(x, file = "polarity.html", open = TRUE, digits = 3, ...)
x |
A |
file |
A name of the html file output. |
open |
logical. If |
digits |
The number of digits to print for each row level average sentiment score. |
... |
Ignored. |
Generates an html document with text highlighting.
library(data.table)
dat <- presidential_debates_2012
setDT(dat)
dat[, gr:={gr= paste(person, time); cumsum(c(TRUE, gr[-1]!= gr[-.N]))}]
dat <- dat[, list(person=person[1L], time=time[1L], dialogue=paste(dialogue,
collapse = ' ')), by = gr][,gr:= NULL][,
dialogue_split := get_sentences(dialogue)][]
(sent_dat <- with(dat, sentiment_by(dialogue_split, list(person, time))))
## Not run:
highlight(sent_dat)
## tidy approach
library(dplyr)
library(magrittr)
cannon_reviews %>%
mutate(review_split = get_sentences(text)) %$%
sentiment_by(review_split, number) %>%
highlight()
## End(Not run)