I used a R package written by other people. In the package, it is supposed to create a file name as "Mar.12". However the file name is "三月.12” in my system since I am running it on an OS with Chinese language (windows 10). I have changed the display language to English in the Rconsole file but it does not help. I am wondering is there any method to change the default date to English in R without revising the original package?
Thanks in advance for help!
Dates in R display in a string format and can be output in various ways, the default being YYYY-MM-DD. The most commonly used symbols to format dates are given in the table below.
You may select the language of R‑Studio main panel and its help. To do so, select an available language on Change Language on the Help menu. You may set which panels and bars to enable/disable. Sometimes, there may be a lot of similar objects in the Drives panel.
To format = , provide a character string (in quotes) that represents the current date format using the special “strptime” abbreviations below. For example, if your character dates are currently in the format “DD/MM/YYYY”, like “24/04/1968”, then you would use format = "%d/%m/%Y" to convert the values into dates.
Unless you need the list nature of the POSIXlt class, the POSIXct class is the usual choice for storing dates in R. If your input date/times are stored as the number of seconds from January 1, 1970, you can create POSIX date values by assigning the appropriate class directly to those values.
More info : https://stat.ethz.ch/R-manual/R-devel/library/base/html/locales.html
You'll get all your local variables through : sessionInfo()
Sys.getlocale()
Sys.getlocale("LC_TIME")
OK, as a Q&A site, it seems an answer is required. From your description, it appears to be the issue of your locales. Read ?locales
for more.
You can have a test with this (read ?strptime
for various format, and pay special attention to those sensitive to locales):
format(Sys.Date(), format = "%Y-%b-%d")
# [1] "2016- 9月-06"
The output has the month in Chinese. If I want to change the display, I need to set "LC_TIME"
locale to "C"
:
Sys.setlocale("LC_TIME", "C")
Then it is OK:
format(Sys.Date(), "%Y-%b-%d")
# [1] "2016-Sep-06"
Every time you start a new R session, you get back to native setting. Should you want a permanent change, put
.First <- function() {
Sys.setlocale("LC_TIME", "C")
}
in the $(R RHOME)/etc/Rprofile.site
file. Read ?Startup
for how to customize R startup and the use of .First
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With