Sys.getlocale & Sys.setlocale Functions in R (2 Examples)
In this tutorial, I’ll demonstrate how to query and set aspects of the locale using the Sys.getlocale and Sys.setlocale functions in the R programming language.
Table of contents:
Let’s dive right into the examples.
Example 1: Query Aspects of the Locale Using Sys.getlocale() Function
In this example, I’ll demonstrate how to get certain aspects of the locale (i.e. the internationalization of a program) using the Sys.getlocale function in R.
Consider the following R code:
Sys.getlocale() # Apply Sys.getlocale function # [1] "LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252"
As you can see, the previous output of the RStudio console has returned some aspects of the locale.
Example 2: Set Aspects of the Locale Using Sys.getlocale() Function
The following syntax explains how to change aspects of the locale using the Sys.setlocale command:
Sys.setlocale("LC_ALL", "German") # Apply Sys.setlocale function
For more information on how to query and set locales, have a look at the documentation of these functions.
Video & Further Resources
Do you need further explanations on the R codes of this tutorial? Then I can recommend watching the following video on my YouTube channel. In the video, I show the content of this page:
The YouTube video will be added soon.
In addition, you might have a look at the other tutorials which I have published on this homepage. You can find some tutorials below.
- Sys.getenv Function in R
- Sys.chmod Function in R
- System Calls & Commands
- R Functions List (+ Examples)
- Introduction to R Programming
In this R tutorial you have learned how to use the Sys.getlocale and Sys.setlocale functions. Please let me know in the comments, if you have additional questions or comments. In addition, don’t forget to subscribe to my email newsletter in order to get updates on the newest posts.
Statistics Globe Newsletter
2 Comments. Leave new
This might work on some systems but not on a current version of Rstudio running R 4.2.0. The help page for Sys.setlocale() makes it clear that the designations of locale is highly system specific.
Hi David,
Thank you for the hint! Do you know an alternative which is independent of the system?
Regards,
Joachim