How to do encoding in R and why ’ comes instead of apostrophe(')s and how to resolve it

Viewed 3935

Hi I am trying to do text mining in R version 3.4.2 I am trying to import .txt files from local drive using VCorpus command. But after Run following code

cname <- file.path("C:", "texts")  
cname  
dir(cname) 
library(readr)
library(tm)
docs <- VCorpus(DirSource(cname))   
summary(docs)
inspect(docs[1])
writeLines(as.character(docs[1]))

Output: Well, the election, it came out really well. Next time we**’**ll triple the number and so on

’ its originally aporstophe(')s now how can i convert or get original text in Rstudio?

Please it will appreciate if someone help me Thanks in Advance

2 Answers

I solved this a different way.

I found that apostrophes that looked like this: ' would render properly, while ones that looked slightly different, like this: ’ would not.

So, for any text that I was printing, I converted ’ to ' like this:

  mytext <- gsub("’", "'", mytext )

Tada... no more issues with "’".

Related