我要在R中保存TM语料库。
writeCorpus(as.character(thecrp), dirdst, filenames = NULL)
一切正常,直到出现错误:
Error in UseMethod("meta", x) : no method applicable for meta applicable to an object of class "character"
NB。我在语料库的每个文档中添加了三个自定义元字段。
以下是可重现的示例:
# Create corpus from a folder of documents on disk
thetxts <- readtext(pthtxt, cache = FALSE)
thecrp <- corpus(thetxts)
# Add docvars (= columns)
# Reference
# NOTE: Add Meta to the corpus
meta(thecrp, tag = "doctyp", type = "corpus") <- "Reports, 2018"
# NOTE: Add Meta to each of the documents
for (i in 1:length(thecrp)){
# ID derived from the name of the file (withdraw .txt)
meta(thecrp[[i]], tag = "id", type = "indexed") <- gsub("\\.txt", "", meta(thecrp[[i]], tag = "id", type = "indexed"))
# constants
meta(thecrp[[i]], tag = "author", type = "indexed") <- "author"
meta(thecrp[[i]], tag = "type", type = "indexed") <- "individual"
meta(thecrp[[i]], tag = "prov", type = "indexed") <- "ocr"
}
# Then I perform usual and **mildly** transformative actions on the corpus
...
# Then I save it to disk: the **error occurs here**
dirdst <- "~/test"
writeCorpus(as.character(thecrp), dirdst, filenames = NULL)