2

I am having an issue creating a DTM after running some code to clean the textual elements within a corpus.

# load data
toothbrush <- read.csv("toothbrushtext.csv", stringsAsFactors = FALSE)

# Collapse text columns

toothbrushtext <- unite(toothbrush, Text, Title.Text, Bullet.Points, 
Product.Description, sep = " ")

# Place into corpus
toothbrushcorpus <- VCorpus(VectorSource(toothbrushtext$Text))

# Run various cleaning steps (only show some here)

toothbrushcorpusclean <- tm_map(toothbrushcorpus, tolower)

toothbrushcorpusclean <- tm_map(toothbrushcorpusclean, removeWords, 
stopwords())

toothbrushcorpusclean <- tm_map(toothbrushcorpusclean, stemDocument)

# Create a Document term Matrix
toothbrushdtm <- DocumentTermMatrix(toothbrushcorpusclean)

# Error: Error in UseMethod("meta", x) : 
no applicable method for 'meta' applied to an object of class "character"

Any idea what might be causing this?

Thanks for the help!

CafeRacer
  • 63
  • 1
  • 10
  • This post https://stackoverflow.com/a/37250415/9731173 suggests that the position of your whitespace stripping code may be a culprit in errors. Might be worth a check. – Pake Aug 18 '18 at 16:48
  • I moved the stripping of whitespace to the end and it is still giving me the same error. Would it have something to do with collapsing columns? – CafeRacer Aug 19 '18 at 01:35
  • 2
    I wrapped all of my tm_map functions with content_transformer and that seemed to have done the trick – CafeRacer Aug 19 '18 at 01:48
  • Could you write an answer on what you exactly did? How did you wrap them with that function? What were the parameters? I have the same problem. – Shayan Nov 16 '21 at 18:29
  • Found a similar question: https://stackoverflow.com/questions/45514472/no-applicable-method-for-tm-map-applied-to-an-object-of-class-character – Shayan Nov 16 '21 at 20:57

0 Answers0