I try to produce a wordcloud and obtain word frequency for a Chinese speech using R, jiebaR and corpus, but cannot make a corpus. Here is my code:
library(jiebaR)
library(stringr)
library(corpus)
cutter <- worker()
v36 <- readLines('v36.txt', encoding = 'UTF-8')
seg_x <- function(x) {str_c(cutter[x], collapse = '')}
x.out <- sapply(v36, seg_x, USE.NAMES = FALSE)
v36.seg <- x.out
v36.seg
library(quanteda)
corpus <- corpus(v36.seg) #Error begins here.
summary(corpus, showmeta = TRUE, 1)
texts(corpus)[1]
tokens(corpus, what = 'fasterword')[1]
tokens <- tokens(v36.seg, what = 'fasterword')
dfm <- dfm(tokens)
dfm
My text file comprises the following paragraphs:
Error begins when I create a corpus. R returns:
Error in corpus.default(v36.seg) :
corpus() only works on character, corpus, Corpus, data.frame, kwic objects.
I don't understand why the text is problematic. Grateful if you can help me solve the problem. Thank you.