执行scores = score.sentiment(ari_txt, pos, neg, .progress='text')时遇报错:对象'ari_txt'未找到
Hey there! Let's break down why you're hitting this error and walk through how to fix it step by step.
The Core Issue
The error Error in inherits(.data, "split") : object 'ari_txt' not found means exactly what it says: R can't find a variable named ari_txt in your current working environment. This is one of the most common R errors, and it's usually easy to resolve.
Step-by-Step Fixes
First, verify if
ari_txtexists at all
Run this command in your R console to check:exists("ari_txt")If it returns
FALSE, you need to create or import theari_txtobject before running your sentiment scoring code.Create or import your text data
Depending on where your text comes from, do one of the following:- If you're working with a local text file: Use
readLines()or a package likereadrto load it:# Example: Load a text file into ari_txt ari_txt <- readLines("your_text_file.txt") - If you're defining text manually: Assign your text directly to
ari_txt:# Example: Create a vector of text strings ari_txt <- c("I love working with sentiment analysis", "This project feels frustrating right now")
- If you're working with a local text file: Use
Check for typos and case sensitivity
R is strictly case-sensitive! Double-check that you didn't misspell the variable name—for example,Ari_txt,ariTxt, orari_textwon't be recognized asari_txt.Confirm the variable is in your current environment
Runls()in the console to list all variables in your current workspace. Ifari_txtisn't listed, it's either not created or was created in a different environment (like inside a function).
Example Working Code
Here's a complete example to test with:
# 1. Define your text data ari_txt <- c("This is a positive statement", "I'm feeling really negative today") # 2. Define your positive/negative dictionaries (adjust as needed) pos <- c("positive", "great", "happy") neg <- c("negative", "sad", "frustrated") # 3. Run the sentiment scoring function scores <- score.sentiment(ari_txt, pos, neg, .progress='text')
内容的提问来源于stack exchange,提问作者Hanif Khan

