title: How to remove non UTF-8 characters from text
body: <p>I need help removing non UTF-8 character from my word cloud. So far this is my code. I've tried gsub and removeWords and they are still there in my word cloud and I do not know what to do to get rid of them. Any help would be appreciated. Thank you for your time.</p>
  
  <p><a href="https://i.stack.imgur.com/GpHiT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GpHiT.png" alt="enter image description here"></a></p>
  
  <pre><code>txt &lt;- readLines("11-0.txt")
  corpus = VCorpus(VectorSource(txt))
  gsub("â€™","â€˜","",txt)
  
  corpus = tm_map(corpus, content_transformer(tolower))
  corpus = tm_map(corpus, removeWords, stopwords("english"))
  corpus = tm_map(corpus, removePunctuation)
  corpus = tm_map(corpus, stripWhitespace) 
  corpus = tm_map(corpus, removeWords, c("gutenberg","gutenbergtm","â€","project"))
  
  tdm = TermDocumentMatrix(corpus)
  m = as.matrix(tdm)
  v = sort(rowSums(m),decreasing = TRUE)
  d = data.frame(word=names(v),freq=v)
  
  wordcloud(d$word,d$freq,max.words = 20, random.order=FALSE, rot.per=0.2, colors=brewer.pal(8, "Dark2"))
  </code></pre>
  
  <p>Edit: Here is my inconv version</p>
  
  <pre><code>txt &lt;- readLines("11-0.txt")
  Encoding(txt) &lt;- "latin1"
  iconv(txt, "latin1", "ASCII", sub="")
  
  corpus = VCorpus(VectorSource(txt))
  corpus = tm_map(corpus, content_transformer(tolower))
  corpus = tm_map(corpus, removeWords, stopwords("english"))
  corpus = tm_map(corpus, removePunctuation)
  corpus = tm_map(corpus, stripWhitespace) 
  corpus = tm_map(corpus, removeWords, c("gutenberg","gutenbergtm","project"))
  
  tdm = TermDocumentMatrix(corpus)
  m = as.matrix(tdm)
  v = sort(rowSums(m),decreasing = TRUE)
  d = data.frame(word=names(v),freq=v)
  
  wordcloud(d$word,d$freq,max.words = 20, random.order=FALSE, rot.per=0.2, colors=brewer.pal(8, "Dark2"))
  title(main="Alice in Wonderland word cloud",font.main=1,cex.main =1.5)
  </code></pre>