Wednesday, 11 September 2013

How do you silently save an inspect object in R's tm package?

How do you silently save an inspect object in R's tm package?

When I save the inspect() object in R's tm package it prints to screen. It
does save the data that I want in the data.frame, but I have thousands of
documents to analyze and the printing to screen is eating up my memory.
library(tm)
data("crude")
matrix <- TermDocumentMatrix(corpus,control=list(removePunctuation = TRUE,
stopwords=TRUE))
out= data.frame(inspect(matrix))
I have tried every trick that I can think of. capture.output() changes the
object (not the desired effect), as does sink(). dev.off() does not work.
invisible() does nothing. suppressWarnings(), suppressMessages(), and
try() unsurprisingly do nothing. There are no silent or quiet options in
the inspect command.
The closest that I can get is
out= capture.output(inspect(matrix))
out= data.frame(out)
which notably does not give the same data.frame, but pretty easily could
be if I need to go down this route. Any other (less hacky) suggestions
would be helpful. Thanks.
Windows 7 64- bit R-3.0.1 tm package is the most recent version (0.5-9.1).

No comments:

Post a Comment