50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

sentimentr (version 0.4.0)

highlight: Polarity Text Highlighting

Description

Highlight sentences within elements (row IDs) by sentiment polarity (positive = green; negative = pink) as an html file.

Usage

highlight(x, original.text = NULL, file = "polarity.html", open = TRUE, digits = 3, ...)

Arguments

x
A sentiment_by object.
original.text
Optional original text (if the user wants to retain all punctuation and capitalization). Default uses the text stored in the sentiment_by object that is striped of many punctuation marks and capitalizations.
file
A nam of the html file output.
open
logical. If TRUE the text highlighting document will attempt to be opened.
digits
The number of digits to print for each row level average sentiment score.
...
Ignored.

Value

Generates an html document with text highlighting.

Examples

Run this code
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][]

(sent_dat <- with(dat, sentiment_by(dialogue, list(person, time))))

## Not run: 
# highlight(sent_dat)
# highlight(sent_dat, original.text = dat[["dialogue"]])
# 
# highlight(with(cannon_reviews, sentiment_by(review, number)))
# ## End(Not run)

Run the code above in your browser using DataLab