Get weekdays in English in R

Printing of Date and POSIX*t objects seems to be controlled by the LC_TIME locale category.

On Windows, you change it like this:

## First, save the current value so we can restore it later
Sys.getlocale("LC_TIME")
# [1] "English_United States.1252"

## First in Spanish
Sys.setlocale("LC_TIME","Spanish Modern Sort")
# [1] "Spanish_Spain.1252"
weekdays(Sys.Date()+0:6)
# [1] "lunes"     "martes"    "miércoles" "jueves"    "viernes"   "sábado"   
# [7] "domingo"  

## Then back to (US) English
Sys.setlocale("LC_TIME","English United States")
# [1] "English_United States.1252"
weekdays(Sys.Date()+0:6)
# [1] "Monday"    "Tuesday"   "Wednesday" "Thursday"  "Friday"    "Saturday" 
# [7] "Sunday" 

On most *NIXes, the equivalent would be:

Sys.setlocale("LC_TIME", "en_US")

The particular locale names are OS-dependent, as mentioned in ?Sys.setlocale. For names accepted by Windows, see here. For names accepted by Linux, see here.


Sys.setlocale("LC_TIME", "C")

did the trick for me. Also this don't bring us OS reports request to set locale to "EN" cannot be honored error message.


From my answer here, you can get weekdays in English without messing with locales like this:

c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
  "Friday", "Saturday")[as.POSIXlt(Day)$wday + 1]