我正在尝试重现这种情绪分析的例子:https://www.kaggle.com/rtatman/tutorial-sentiment-analysis-in-r
我有一个" file.txt"我希望在" ../ input"中分析的文本文件夹中。
library(tidyverse)
library(tidytext)
library(glue)
library(stringr)
library(dplyr)
require(plyr)
# get a list of the files in the input directory
files <- list.files("../input")
fileName <- glue("../input/", files[1], sep = "")
fileName <- trimws(fileName)
fileText <- glue(read_file(fileName))
fileText <- gsub("\\$", "", fileText)
tokens <- data_frame(text = fileText) %>% unnest_tokens(word, text)
但在此行之后
#get the sentiment from the first text:
tokens %>%
inner_join(get_sentiments("bing")) %>% # pull out only sentiment words
count(sentiment) %>% # count the # of positive & negative words
spread(sentiment, n, fill = 0) %>% # made data wide rather than narrow
mutate(sentiment = positive - negative) # # of positive words - # of negative owrds
我收到错误消息
计数错误(。,情绪):对象&#39;情绪&#39;找不到
昨天相同的代码工作正常,今天我收到此错误。问题似乎是由plyr
包引起的。在plyr
之前加载dplyr
时似乎工作正常,但现在即使按顺序加载也会出错。