gpt4 book ai didi

R tm In mclapply(内容(x),FUN,...): all scheduled cores encountered errors in user code

转载 作者:行者123 更新时间:2023-12-03 00:12:04 45 4
gpt4 key购买 nike

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

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

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

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

以下链接是一个可重现的示例,我们可以将其复制/粘贴到 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

最佳答案

尝试使用如下代码:

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

我认为新的tm包明确要求这一点。

关于R tm In mclapply(内容(x),FUN,...): all scheduled cores encountered errors in user code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25069798/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com