Presentations (slidify and Rpres) with Latin characters (ç, ã, é...) corrupted

Asked

Viewed 314 times

3

I am preparing slides in R, but the Latin characters (ç, ã, é etc...) get corrupted when the presentation is compiled. I tried both with slidify and with Rpre, same problem. Someone knows how to solve?

Editing: If you are inside the same section, in R studio, click on:

file> "save with encoding" > UTF8

this solves the problems when it comes to visualizing. But a new problem arises:

After saving, when I restart a new section of Rstudio and reopen the file the source code appears all 'corrupted' (ex: "attention" turns : "attention§"). However the compiled version remains correct ("attention").

I tried again to use "save with encoding", to continue editing the text, but then it erodes the visalization (compiled version) of the previous text.

Does anyone have any idea how to fix this?

Systema: Windows 8.1 64bits, R version 3.1.1, Rstudio 0.98.1017

  • 1

    if Voce save with utf8 encoding does not work?

  • Yeah, in Rstudio, when I save a Markdown file it asks this encoding question and when I compile it is right. But when and create the R Presentation it does not ask that. How would you set the encoding

  • when there is some wrong code in the presentation this error also appears to me

  • Windows or Linux? I think it’s OS problem... I have these problems in Windows, but not in linux.

  • windows, edited above

  • The default of Windows is usually latin1 (iso 8859-1) tries to warn with this encoding instead of utf-8. You are probably saving with utf-8 and then opening in latin1 (which is the default) so the strange characters appear.

Show 1 more comment

2 answers

3

I figured out how to do it. In R studio, click on:

file> "save with encoding" > UTF8

this solves the problems when viewing

In the matter of reopening the file in a new section of Rstudio and being able to visualize correctly and then adding new contents:

  • open the file
  • file > reopen with encoding > UTF8

everything works again

  • Lucas, this does not solve the problem ? If no please delete the answer

  • tries to use reopen with encoding in Rstudio

  • 1

    @gmsantos: I edited the question to include the above answer. Ok, I will delete

2

Windows default is latin1 (iso 8859-1) and Rpres is generating the HTML file as UTF-8.

When you save the file with the UTF-8 encoding, then the HTML and the source file will be equal and the characters will appear correctly.

When you close Rstudio and reopen the file, as the default is latin1, but the file is as UTF-8, the characters will appear "wrong" ( "attention" turns : "attention§"). A "solution" to this is to reopen with the encoding UTF-8 (reopen with encoding) to continue working.

Another option is to do everything in latin1 normally (at first it will seem that html is "wrong") and after you generate html just change the charset: where you have <meta charset="utf-8"> you change to <meta charset="latin1">.

Apparently there is no option to tell Rpres what the encoding of your HTML is. If there was this option, just specify it to look like the encoding of the file . Rpres instead of going to change directly in HTML.

  • Excellent, thank you, Carlos. I’m actually doing everything by Rstudio point-click (in a file .Rpres > "preview" button). I don’t know compiling through the command line there would be a way around it.

  • you had the same problem with Slidify, or it accepts Latin1 more easily?

  • One more addendum (just not to open a new question): I have similar encoding problems with the View() command. Is there any solution for this?

  • 1

    @Lucasmation think for you then the best option would always be to do the reopen with encoding (after saving as UTF-8). The question of View is the same "problem". Rstudio is actually a browser (in HTML and javascript) and it opens windows as pages in UTF-8. But when we create our variables, they are in latin1 (see this doing x <- "ã"; Encoding(x). Hence the View is not shown correctly (but the data is ok). This also occurs with package help title, unfortunately. As for Slidify, I have to test, because I always used on Mac and there is no problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.