Skip to content
Back to skills

R Nlp Sentiment

ASecurity

R sentiment analysis with tidytext, syuzhet, sentimentr. Use for sentiment scoring and emotion detection.

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 4, 2026
datarust

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill r-nlp-sentiment --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R Nlp Sentiment?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R Nlp Sentiment
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-r-nlp-sentiment/badge)](https://www.skillsdirectory.com/skills/leolin990405-r-nlp-sentiment)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: r-nlp-sentiment
description: R sentiment analysis with tidytext, syuzhet, sentimentr. Use for sentiment scoring and emotion detection.
---

# R Sentiment Analysis

Sentiment and emotion detection.

## tidytext Lexicons

```r
library(tidytext)
library(dplyr)

# Available lexicons
get_sentiments("afinn")   # Score -5 to +5
get_sentiments("bing")    # positive/negative
get_sentiments("nrc")     # 8 emotions + pos/neg

# Sentiment analysis
df %>%
  unnest_tokens(word, text) %>%
  inner_join(get_sentiments("bing")) %>%
  count(document, sentiment) %>%
  pivot_wider(names_from = sentiment, values_from = n, values_fill = 0) %>%
  mutate(sentiment = positive - negative)

# AFINN scoring
df %>%
  unnest_tokens(word, text) %>%
  inner_join(get_sentiments("afinn")) %>%
  group_by(document) %>%
  summarise(sentiment = sum(value))

# NRC emotions
df %>%
  unnest_tokens(word, text) %>%
  inner_join(get_sentiments("nrc")) %>%
  count(sentiment, sort = TRUE)
```

## syuzhet

```r
library(syuzhet)

# Get sentiment scores
sentiment <- get_sentiment(texts, method = "syuzhet")
sentiment <- get_sentiment(texts, method = "bing")
sentiment <- get_sentiment(texts, method = "afinn")
sentiment <- get_sentiment(texts, method = "nrc")

# NRC emotions
emotions <- get_nrc_sentiment(texts)
# Returns: anger, anticipation, disgust, fear, joy, sadness, surprise, trust, negative, positive

# Plot emotional arc
plot(sentiment, type = "l")

# Sentiment by sentence
sentences <- get_sentences(text)
sent_values <- get_sentiment(sentences)

# Smooth sentiment arc
smoothed <- get_dct_transform(sent_values, low_pass_size = 5)
plot(smoothed, type = "l")
```

## sentimentr

```r
library(sentimentr)

# Sentence-level sentiment (handles negation, amplifiers)
result <- sentiment(texts)
result <- sentiment_by(texts, by = NULL)  # Aggregate

# With grouping
result <- sentiment_by(df$text, by = df$document)

# Profanity detection
profanity(texts)

# Emotion detection
emotion(texts)

# Highlight sentiment
highlight(sentiment_by(texts))
```

## Custom Lexicons

```r
library(tidytext)

# Create custom lexicon
custom_lexicon <- tibble(
  word = c("excellent", "terrible", "amazing", "awful"),
  sentiment = c("positive", "negative", "positive", "negative")
)

# Use custom lexicon
df %>%
  unnest_tokens(word, text) %>%
  inner_join(custom_lexicon)

# Domain-specific (finance)
library(lexicon)
hash_sentiment_loughran_mcdonald  # Financial sentiment
```

## Visualization

```r
library(ggplot2)

# Sentiment over time
df %>%
  unnest_tokens(word, text) %>%
  inner_join(get_sentiments("bing")) %>%
  count(date, sentiment) %>%
  pivot_wider(names_from = sentiment, values_from = n, values_fill = 0) %>%
  mutate(sentiment = positive - negative) %>%
  ggplot(aes(date, sentiment)) +
  geom_line() +
  geom_smooth()

# Word contribution
df %>%
  unnest_tokens(word, text) %>%
  inner_join(get_sentiments("bing")) %>%
  count(word, sentiment, sort = TRUE) %>%
  group_by(sentiment) %>%
  slice_max(n, n = 10) %>%
  ggplot(aes(reorder(word, n), n, fill = sentiment)) +
  geom_col() +
  coord_flip() +
  facet_wrap(~sentiment, scales = "free_y")
```

Files in this skill

  • SKILL.md3.1 KB
  • sentimentr/SKILL.md3.5 KB
  • syuzhet/SKILL.md3.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…