twt [[1]]中的错误:类型'闭包的对象'不是子集

时间:2018-03-24 02:26:49

标签: r

我是新手编程并收到如下错误。

  

twt [[1]]中的错误:类型'闭包的对象'不是子集表格

我的代码:

myfun <- function(x){
mycorpus <- Corpus(VectorSource(x))
mycorpus <- tm_map(mycorpus, content_transformer(function(x) iconv(enc2utf8(x), sub = "byte")))
mycorpus <- tm_map(mycorpus, content_transformer(tolower))
removeURL <- function(x) gsub("https://['[:space:]]*","",x)
mycorpus <- tm_map(mycorpus, content_transformer(removeURL))
removeNL <- function(x) gsub("[^[:alpha:][:space:]]*","",x)
mycorpus <- tm_map(mycorpus, content_transformer(removeNL))
mycorpus <- tm_map(mycorpus, removeWords, stopwords("english"))
mycorpus <- tm_map(mycorpus, stripWhitespace)
mycorpus <- tm_map(mycorpus, stemDocument)

stemCompletion2 <- function(x,dictionary) {
  x <- unlist(strsplit(as.character(x), ""))
  #Removing empty string 
  x <- x[x !=""]
  x <- stemCompletion(x, dictionary =dictionary)
  x <- paste(x, sep = "", collapse = "")
  PlainTextDocument(stripWhitespace(x))
  mycorpus <- tm_map(mycorpus, content_transformer(stemCompletion2), dictionary=mycorpus)
  return(mycorpus)
}
}

twt<- myfun(twetL)
strwrap(as.character(twt[[1]]))
  • 执行代码
  • 后出错

0 个答案:

没有答案