Is there a way to keep non-english characters in the source code after compiling an RMarkdown document?

Hi,
I am writing a report in Spanish with RMarkdown in Rstudio. The words with accents are seen nicely in the html, but, because I need to save the .Rmd file with UTF-8 encoding, the accented characters are no longer readable in the .Rmd file. The default encoding in my computer Windows OS is ISO-8859-1. Can I do something to solve this problem?
Thanks
Luis

1 Like

If you need files with a different encoding than the default, I think you have to 'Save with encoding' before writing anything. Non-English characters tend to get lost in conversion from one encoding to another.

I don't know if copy-paste the text you already have from the ISO-8859-1 document to the UTF-8 file, can save the text you already have.

HTH
Ulrik

2 Likes

Thanks for your kind response.
The need to save the file with a different encoding than the default, is because knitr only works with this encoding, if I don´t change it, the rendering fails miserably.
I followed your suggestions, but nothing worked. However, your gave me the way to circumbent the problem. As long as I don't close the file, the spanish characters are conserved. I compile all the times I want, without never closing the file. Before closing the .Rmd file y save it with the default encoding et voilá. I will stick somewhere a remainder: "change the encoding before closing".
Encoding in Windows sucks, somebody said.
Thanks and take care.
Luis

1 Like

If you already wrote you text file (Rmd here) using Windows OS ISO-8859-1 encoding, you need to convert the Rmd file to utf8. "Save with encoding" should work as adviced previously.

For rmarkdown and knitr to work best, you should always work with UTF8 file.

With RStudio, you can configure the editor to always work in UTF8.

3 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.