sentimentRPy Package

R Package
An R package for sentence-level and word-level sentiment analysis.
Author
Affiliation

Xinzhuo Huang

HKUST SOSC

Published

June 10, 2023

Modified

February 16, 2024

Overview

An R package for sentence-level and word-level sentiment analysis. Support vectorization, multithreading and is robust to errors.



Installation

remotes::install_github("xinzhuohkust/sentimentRPy")

Usage

R

word level

sentimentRPy::get_sentimentR(
    text = c("I am happy", "I am sad"),
    method = "word"
    )
neu pos neg
0 3 0
0 0 -2

Sentence level which will take the contrast and negation into account. sd will be provided when there are multiple sentences. The underlying function is from sentimentr.

sentimentRPy::get_sentimentR(
    text = "I am not happy, but I am also not unhappy.",
    method = "sentence"
    )
sentiment sd
0.296463530640786 NA

Multithreading model using all available CPU cores.

sentimentRPy::get_sentimentR(
    text = a large corpus,
    method = "sentence", # or word
    multisession = TRUE
    )

Python

Python setup

asent <- sentimentRPy::asent_setup(python = "C:\\Users\\xhuangcb\\anaconda3\\envs\\pytorch_gpu\\python.exe")

Sentence level sentiment analysis using asent in Python

sentimentRPy::get_sentimentPy("I am not happy, but I am also not unhappy.")
neg neu pos compound
0 0.652 0.348 0.652