Search code examples
rterm-document-matrix

Error: inherits(doc, "TextDocument") is not TRUE


I am running the following code chunk

tdm = TermDocumentMatrix(ctext,control=list(minWordLength=1))
print(tdm)

inspect(tdm[10:20,11:18])

out = findFreqTerms(tdm,lowfreq=5)
print(out)

When I run it in console it runs fine. However when I include it as part of a RMD and try to Knit HTML (ioslides) I get an error:

Error:

inherits(doc, "TextDocument") is not TRUE


Solution

  • I had the same problem.

    The problem is basically with the version of tm package. You can't really help it.

    Use content_transformer function in tm_map function. It resolved the error for me.

    Hope it helps.