Inside the function, I want to change the locale, do something, and then replace it. Because the side effects are bad.
old_locale <- Sys.getlocale() # do some stuff Sys.setlocale(old_locale)
However, Sys.setlocale requires the category and locale argument.
Sys.getlocale() , Sys.getlocale() other hand, gives me the following:
"LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252"
Ok Maybe I can handle this:
old_locale <- Sys.getlocale() locale_key_values <- strsplit(strsplit(old_locale, ';')[[1]], '=')[[1]], '=') locale_keys <- lapply(locale_key_values, getElement, name=1) locale_values <- lapply(locale_key_values, getElement, name=2)
The problem is solved!
... or that?
Sys.setlocale(locale='C')
Sys.getlocale() now returns "C" ! This will not work with my keyword parser.
And I suddenly realize that I donβt know anything about locales or the range of strings that Sys.getlocale() can return.
Does anyone know of a reliable way to save and restore locale state?
source share