为什么我不能创建文档术语矩阵?

时间:2016-10-28 17:22:31

标签: r term-document-matrix

我使用的是R 3.3.0,由于某些原因,我无法在没有收到错误的情况下创建DTM:

Error in UseMethod("meta", x) : 
  no applicable method for 'meta' applied to an object of class "try-error"
In addition: Warning messages:
1: In mclapply(x$content[i], function(d) tm_reduce(d, x$lazy$maps)) :
  all scheduled cores encountered errors in user code
2: In mclapply(unname(content(x)), termFreq, control) :
  all scheduled cores encountered errors in user code
The weird thing is, this error occurred only recently. I tried it before and it worked fine.

下面我粘贴了我使用的代码:

#pre-processing and transforming the corpus
myStopwords<- c(stopwords("english"), stopwords("SMART"))

my_corpus <- tm_map(corpus, content_transformer(tolower),lazy=TRUE)
my_corpus <- tm_map(my_corpus, removeWords, myStopwords, lazy=TRUE)
my_corpus <- tm_map(my_corpus, removeNumbers, lazy=TRUE)
my_corpus <- tm_map(my_corpus, removePunctuation, lazy=TRUE)
my_corpus <- tm_map(my_corpus, stripWhitespace, lazy=TRUE)
my_corpus <- tm_map(my_corpus, stemDocument, lazy=TRUE)
my_corpus <- tm_map(my_corpus, PlainTextDocument, lazy=TRUE)
my_corpus <- tm_map(my_corpus, content_transformer(function(x) iconv(x, to='UTF-8-MAC', sub='byte')), mc.cores=1, lazy=TRUE)

我在稍后阅读有关此错误的stackoverflow上的其他帖子后添加的最后两行。但是,它仍然无效。

myDtm <- DocumentTermMatrix(
  my_corpus, control=list(
  wordLengths=c(3,Inf) 
)
)

sessioninfo()

R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] wordcloud_2.5      RColorBrewer_1.1-2 slam_0.1-35       
[4] SnowballC_0.5.1    tm_0.6-2           NLP_0.1-9         

loaded via a namespace (and not attached):
[1] parallel_3.3.0 tools_3.3.0    Rcpp_0.12.5   

我需要为我的硕士论文运行这个。我是R的初学者,我真的希望有人可以帮助我!

0 个答案:

没有答案