Character Encoding


Character Encoding

Starting with version 0.93, RStudio supports non-ASCII characters for input and output.


Unicode characters can be used for both input and output in the console.

Source Editor

The RStudio source editor natively supports Unicode characters. It will allow you to type or paste characters from any language, even ones that are not part of the document's character set. RStudio will allow you to save such documents, but will print a warning to the R console that not all characters could be encoded. If you close the document without re-saving in a more suitable encoding, those characters will be lost.

If in doubt about which encoding to use, use UTF-8, as it can encode any Unicode character.

Reading and Writing Files

The RStudio source editor can read and write files using any character encoding that is available on your system:

  • You can choose the encoding for reading with File : Reopen with Encoding, which will re-read the current file from disk with the new encoding.
  • You can also save an open file using a different encoding with File : Save with Encoding.

The Reopen and Save with Encoding commands both display the following dialog:

Setting the Default Encoding

If you frequently use the character set, check "Set as default encoding for source files". You can view or change this default in the Tools : Options (for Windows & Linux) or Preferences (for Mac) dialog, in the General section.

If you don't set a default encoding, files will be opened using UTF-8 (on Mac desktop, Linux desktop, and server) or the system's default encoding (on Windows). When saving a previously unsaved file, RStudio will ask you to choose an encoding if non-ASCII characters are present.

Known Issues

  • If you call Sys.setlocale with "LC_CTYPE" or "LC_ALL" to change the system locale while RStudio is running, you may run into some minor issues as RStudio assumes the system encoding doesn't change. If you are on Windows, we recommend you only call Sys.setlocale in .Rprofile. If you are on Mac or Linux and want to change the system locale, please visit the support forum and let us know your scenario.
  • On Windows, R's source function does not work with files that include characters that aren't part of the current system encoding. You may have trouble with RStudio's Run All and Source on Save commands, as they rely on source.
Have more questions? Submit a request


Powered by Zendesk