R tm In mclapply(content(x), FUN, …) : all scheduled cores encountered errors in user code

99封情书 提交于 2019-11-26 20:39:37

问题


When I run the following codes to the penultimate line, I got Warning message:

In mclapply(content(x), FUN, ...) : all scheduled cores encountered errors in user code

When I run the final line, I got

"Error in UseMethod(\"words\") : \n no applicable method for 'words' applied to an object of class \"character\"\n" attr(,"class") "try-error" attr(,"condition")

The following link is a reproducible example which we can copy/paste into R and run.

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

I just start learn R and I'll be appreciate your help.

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 

回答1:


Try using the code as follows:

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

I think the new tm package requires this explicitly.




回答2:


I tried the solution provided by @Charles Copley but did not work in my code. For later google searchers, another alternative solution is to set the number of cores to 1.

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

This post tm_map has parallel::mclapply error in R 3.0.1 on Mac provided a useful explanation.



来源:https://stackoverflow.com/questions/25069798/r-tm-in-mclapplycontentx-fun-all-scheduled-cores-encountered-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!