highlight: Polarity Text Highlighting

Description Usage Arguments Value Examples

View source: R/highlight.R

Description

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

Usage

1
2
3
4
5
6
7
highlight(
  x,
  file = file.path(tempdir(), "polarity.html"),
  open = TRUE,
  digits = 3,
  ...
)

Arguments

x

A sentiment_by object.

file

A name 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

 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
## Not run: 
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))))

highlight(sent_dat)

## tidy approach
library(dplyr)
library(magrittr)

hu_liu_cannon_reviews %>%
    filter(review_id %in% sample(unique(review_id), 3)) %>%
    mutate(review = get_sentences(text)) %$%
    sentiment_by(review, review_id) %>%
    highlight()

## End(Not run)

Example output

       person   time word_count        sd ave_sentiment
 1:     OBAMA time 1       3599 0.2535006    0.12256892
 2:     OBAMA time 2       7477 0.2524864    0.11277349
 3:     OBAMA time 3       7243 0.2476204    0.08085711
 4:    ROMNEY time 1       4085 0.2525596    0.10151917
 5:    ROMNEY time 2       7536 0.2211657    0.08838090
 6:    ROMNEY time 3       8303 0.2641706    0.10197611
 7:   CROWLEY time 2       1672 0.2187178    0.19455947
 8:    LEHRER time 1        766 0.2887731    0.15946408
 9:  QUESTION time 2        583 0.1802807    0.03203141
10: SCHIEFFER time 3       1445 0.2353635    0.08843984
Saved in /work/tmp/tmp/RtmpmYN2Uk/polarity.html
Opening /work/tmp/tmp/RtmpmYN2Uk/polarity.html ...
sh: 1: xdg-open: Permission denied

Attaching package:dplyrThe following objects are masked frompackage:data.table:

    between, first, last

The following objects are masked frompackage:stats:

    filter, lag

The following objects are masked frompackage:base:

    intersect, setdiff, setequal, union

Saved in /work/tmp/tmp/RtmpmYN2Uk/polarity.html
Opening /work/tmp/tmp/RtmpmYN2Uk/polarity.html ...
sh: 1: xdg-open: Permission denied

sentimentr documentation built on Oct. 12, 2021, 9:06 a.m.