Problem with script encoding

I'm experiencing the following problem. When I use and save a script, often I use non-ascii characters like ç ã á (my native language is Portuguese). Just after I save my file, and open like the next day, everything is fine, but after some weeks, I tend to find problems with the encoding, with all the characters being substituted by ?. What is weird is that it doesn't happen immediately, just after some days for some reason.

The default text encoding in my R Studio is UTF-8. I tend to use projects in R Studio. I recently updated R and R Studio, but this happened previously, so it doesn't seem to be the problem. All my projects are saved in a folder at OneDrive.

Any clues? And is it possible to fix this scripts so I don't need to change the code by hand? I tried to save the script in different encodings, but with no success.

This is the default config from my system:

> devtools::session_info()
- Session info ------------------------------------------------------------------------
 setting  value                       
 version  R version 4.0.2 (2020-06-22)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  Portuguese_Brazil.1252      
 ctype    Portuguese_Brazil.1252      
 tz       America/Sao_Paulo           
 date     2020-10-06

Thanks a lot.

User Tarqon at Reddit gave a solution

I think Rstudio just forgets it default text encoding the moment you restart it? I have had this issue as well.
When you notice the problem happening, no information has been lost. You can do file > reopen with encoding and that will fix it. Maybe put some 'canary' characters at the top so you notice quickly.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.