我正在尝试重现这个情绪分析的例子: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
我收到一条错误消息
计数错误(。,情绪):找不到对象“情绪”
昨天同样的代码运行良好,今天我得到了这个错误。看来问题是由plyr
包装引起的。plyr
之前加载时似乎工作正常dplyr
,但现在即使按该顺序加载也会出错。