【问题标题】:R tm In mclapply(content(x), FUN, ...) : all scheduled cores encountered errors in user codeR tm In mclapply(content(x), FUN, ...) : 所有计划的核心在用户代码中遇到错误
【发布时间】:2014-09-24 00:59:38
【问题描述】:

当我将以下代码运行到倒数第二行时,我收到了警告消息:

在 mclapply(content(x), FUN, ...) 中:遇到的所有调度核心 用户代码错误

当我运行最后一行时,我得到了

"UseMethod(\"words\") 中的错误:\n 没有适用的方法 'words' 应用于类 \"character\"\n" attr(,"class") 的对象 "try-error" attr(,"条件")

以下链接是一个可重现的示例,我们可以将其复制/粘贴到 R 中并运行。

https://github.com/weijia2013/mclapply-issue/blob/master/codes

我刚开始学习 R,非常感谢您的帮助。

library(devtools)
install_github("twitteR", username="geoffjentry")
library(twitteR)
setup_twitter_oauth("API Key", "API Secret")

rdmTweets <- userTimeline('rdatamining', n=200)
(nDocs <- length(rdmTweets))
rdmTweets[11:15]
for (i in 11:15) {cat(paste("[[", i, "]] ", sep="")) + writeLines(strwrap(rdmTweets[[i]]$getText(), width=73))}

df <- do.call("rbind", lapply(rdmTweets, as.data.frame))
dim(df)
library(tm)
library(SnowballC)
library(RWeka)
library(rJava)
library(RWekajars)

myCorpus <- Corpus(VectorSource(df$text))
myCorpus <- tm_map(myCorpus, tolower)
myCorpus <- tm_map(myCorpus, removePunctuation)
myCorpus <- tm_map(myCorpus, removeNumbers)
removeURL <- function(x) gsub("http[[:alnum:]]*", "", x)
myCorpus <- tm_map(myCorpus, removeURL)
myStopwords <- c(stopwords("english"), "available", "via")
myStopwords <- setdiff(myStopwords, c("r", "big"))
myCorpus <- tm_map(myCorpus, removeWords, myStopwords)



myCorpusCopy <- myCorpus
myCorpus <- tm_map(myCorpus, stemDocument)
for (i in 11:15) {cat(paste("[[", i, "]] ", sep="")) + writeLines(strwrap(myCorpus[[i]], width=73))}

myCorpus <- tm_map(myCorpus, stemCompletion, dictionary=myCorpusCopy)

inspect(myCorpus[11:15])

sessionInfo()

R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
[1] RWekajars_3.7.11-1 rJava_0.9-6        RWeka_0.4-23      
[4] SnowballC_0.5      tm_0.6             NLP_0.1-3         
[7] twitteR_1.1.8      devtools_1.5      

loaded via a namespace (and not attached):
[1] bit_1.1-12     bit64_0.9-4    digest_0.6.4   evaluate_0.5.5
[5] grid_3.1.1     httr_0.4       memoise_0.2.1  parallel_3.1.1
[9] RCurl_1.95-4.1 rjson_0.2.14   slam_0.1-32    stringr_0.6.2 
[13] tools_3.1.1    whisker_0.3-2 

【问题讨论】:

    标签: r twitter rstudio tm mclapply


    【解决方案1】:

    尝试使用如下代码:

    myCorpus <- tm_map(myCorpus, stemDocument,lazy=TRUE).
    myCorpus <- tm_map(myCorpus, tolower,lazy=TRUE) etc.
    

    我认为新的 tm 包明确要求这样做。

    【讨论】:

    • 这为我解决了 OP 的确切问题。
    • 这为我解决了同样的问题!谢谢@Charles Copley。 :)
    • 为什么下面的语法不正确? myCorpus
    【解决方案2】:

    我尝试了@Charles Copley 提供的解决方案,但在我的代码中不起作用。 对于后来的 google 搜索者,另一种解决方案是将核心数设置为 1。

    corpus = tm_map(corpus, tolower, mc.cores = 1)
    

    这篇帖子tm_map has parallel::mclapply error in R 3.0.1 on Mac 提供了有用的解释。

    【讨论】:

      猜你喜欢
      • 2017-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      相关资源
      最近更新 更多