2017-07-18 20 views
0

私はランダムファイルのセンチメント分析をしようとしています。ただし、スローされたエラーは次のとおりです。エラー:関数 "classify_emotion"を見つけることができませんでした

could not find function "classify_emotion" 

パッケージ「センチメント」は使用できませんでした(Rバージョン3.1.2)。しかし、インストールされたものはinstall_github('sentiment140', 'okugami79')です。

エラーがまだそこにある:could not find function "classify_emotion"

コード:

library(plyr) 
library(ggplot2) 
library(wordcloud) 
library(RColorBrewer) 
library(tm) 
library(SnowballC) 
library(sentiment) 
library(Rcpp) 
skill <- read.csv("C:/Users/632579/Desktop/skill.csv", header=FALSE, comment.char="#") 
df<- data.frame(skill) 
textdata <- df[df$data, ] 
textdata = gsub("[[:punct:]]", "", textdata) 
textdata = gsub("[[:punct:]]", "", textdata) 
textdata = gsub("[[:digit:]]", "", textdata) 
textdata = gsub("http\\w+", "", textdata) 
textdata = gsub("[ \t]{2,}", "", textdata) 
textdata = gsub("^\\s+|\\s+$", "", textdata) 
try.error = function(x) 
{ 
    y = NA 
    try_error = tryCatch(tolower(x), error=function(e) e) 
    if (!inherits(try_error, "error")) 
    y = tolower(x) 
    return(y) 
} 
textdata = sapply(textdata, try.error) 
textdata = textdata[!is.na(textdata)] 
names(textdata) = NULL 
class_emo = classify_emotion(textdata, algorithm="bayes", prior=1.0) 
emotion = class_emo[,7] 
emotion[is.na(emotion)] = "unknown" 
class_pol = classify_polarity(textdata, algorithm="bayes") 
polarity = class_pol[,4] 


sent_df = data.frame(text=textdata, emotion=emotion,polarity=polarity, stringsAsFactors=FALSE) 
sent_df = within(sent_df,emotion <- factor(emotion, levels=names(sort(table(emotion), decreasing=TRUE)))) 
ggplot(sent_df, aes(x=emotion)) + 
geom_bar(aes(y=..count.., fill=emotion)) + 
scale_fill_brewer(palette="Dark2") + 
labs(x="emotion categories", y="") 

ggplot(sent_df, aes(x=polarity)) + 
geom_bar(aes(y=..count.., fill=polarity)) + 
scale_fill_brewer(palette="RdGy") + 
labs(x="polarity categories", y="") 
emos = levels(factor(sent_df$emotion)) 
nemo = length(emos) 
emo.docs = rep("", nemo) 
for (i in 1:nemo) 
{ 
    tmp = textdata[emotion == emos[i]] 
    emo.docs[i] = paste(tmp, collapse=" ") 
} 
emo.docs = removeWords(emo.docs, stopwords("english")) 
corpus = Corpus(VectorSource(emo.docs)) 
tdm = TermDocumentMatrix(corpus) 
tdm = as.matrix(tdm) 
colnames(tdm) = emos 
comparison.cloud(tdm, colors = brewer.pal(nemo, "Dark2"), 
       scale = c(3,.5), random.order = FALSE, 
       title.size = 1.5) 
+1

githubでその関数を見つけることができません。導入された場所を教えてください。 – Masoud

+0

githubで見つけたのと同じパッケージではないと思います。あなたはcranアーカイブのために 'sentiment'パッケージをインストールするか、正しいgithub reposを見つけることができます – cderv

+0

' RTextTools'パッケージをインストールしようとしました –

答えて

0

あなたは、Rの現在のバージョンに更新を検討あなたのパッケージを更新し、その問題を解決していないかどうかを確認すべきです。更新に「installr」パッケージを使用することを検討してください。

機能を直接ロードする場合は、hereにあります。

+0

これを試しました.....しかし、classify_emotion(textdata、algorithm = "bayes" = 1): 関数 "create_matrix"が見つかりません –

+1

関数を直接読み込んだり、Rを更新しようとしましたか? create_matrixは、直接ロードする必要があるパッケージ内の別の関数です。 Rを更新し、install.packages( "sentiment")でパッケージをインストールしようとします。 3.1.2は時代遅れであり、多くのパッケージはこれまでのところ互換性がありません。 – Tiffany

0

しかし、この質問は少し古いものですが、他の誰かが同じ問題に直面した場合は解決策を提供しています。私は同じ/同様の問題を抱えています。

まず、RStem am tmパッケージを別途インストールする必要がありました。その後、ディスクから感情をインストールします。そしてそれはうまくいった。ありがとうございました。

関連する問題