2
votes

I can create a corpus in R but when I try to apply tm_map functions to it I get the following error message:

Error in UseMethod("as.PlainTextDocument", x) : no applicable method for 'as.PlainTextDocument' applied to an object of class "c('PlainTextDocument', 'TextDocument', 'character')"

The code up to that point is:

setwd("C:/…/Documents/TextMining")
webtextGoogle <- GoogleNewsSource("Greek shipping")
GreekShippingContent <- WebCorpus(GoogleNewsSource("Greek shipping"))
writeCorpus(GreekShippingContent, "C:/…/Documents/TextMining", filenames = paste(seq_along(GreekShippingContent), ".txt", sep=""))
GreekShippingContent0 <- Corpus(DirSource("C:/…/Documents/TextMining"), list(reader = readPlain))
GreekShippingContent2 <- tm_map(GreekShippingContent0, as.PlainTextDocument)

I have looked in the documentation and explanations of what this means in related contexts but I cannot understand what to do (not a developer). Can anyone correct the code? I have learned a lot by example. Thanks.

1
BTW I am using packages tm and tm.plugin.webmining. - Dennis
You haven't given us a minimal working example so help is difficult at best. Providing help without data is like the mechanic fixing your car without looking at the car. Even if he has a theory he can't truly test the theory without data. My theory...try lapply(GreekShippingContent0, as.PlainTextDocument) but it's just a guess. - Tyler Rinker
Hi Tyler, and thanks for your answer which I will try right away. As I am new to this kind of board, do you mean to include "inline" data so the code will work as provided? The code I have provided downloads it from Google -- but if practice in stackoverflow is to have inline data, I will do it in the future. Is that what you mean by providing working code? Thanks (and sorry for not doing it as expected :-) ) - Dennis
yes include inline. You can make up a small data set or use dput to help make it. So here's an example where I provide a MWE: stackoverflow.com/questions/19804615/… No worries on the as expected. Every new social situation you have to learn the norms. That's why I said something otherwise you just keep posting and don't get help because you unknowingly violated the norms. - Tyler Rinker
I am providing the part which seems not to be working library(tm.plugin.webmining) GreekShippingContent0 <- "The Greek administration is coming under increasing pressure over it foot-dragging regarding its meeting international convention deadlines, especially when it relies on classification societies as an Recognised Organisation (RO) on its behalf. " GreekShippingContent1 <- tm_map(GreekShippingContent0, as.PlainTextDocument) The error is:Error in UseMethod("tm_map", x) : no applicable method for 'tm_map' applied to an object of class "character" - Dennis

1 Answers

4
votes

This is a shot in the dark because you haven't conveyed the problem in a minimal way. I'd suggest to make changes in your question with code tags rather than as comments. This works:

library(tm)

GreekShippingContent <- "The Greek administration is coming under increasing pressure over it foot-dragging regarding its meeting international convention deadlines, especially when it relies on classification societies as an Recognised Organisation (RO) on its behalf. " 
GreekShippingContent0 <-  Corpus(VectorSource(GreekShippingContent))
tm_map(GreekShippingContent0, PlainTextDocument)

You'll have to do some leg work and apply to your situation.