I was playing around with the setting of the LANGUAGE variable and am wondering whether I'm missing something obvious about resetting the value to its original state once it's been set. I seem to be able to reset the language for warnings/errors once, but not to change it a second time (or reset it) once it's been set ... ?? ## default (no LANGUAGE set, English locale) > sqrt(-1) [1] NaN Warning message: In sqrt(-1) : NaNs produced ## no complaints, doesn't change (as expected) > Sys.setenv(LANGUAGE = "en") > sqrt(-1) [1] NaN Warning message: In sqrt(-1) : NaNs produced ## change to German > Sys.setenv(LANGUAGE = "de") > sqrt(-1) [1] NaN Warnmeldung: In sqrt(-1) : NaNs wurden erzeugt ## try to change to Spanish - no luck ## (this does work in a clean session) > Sys.setenv(LANGUAGE = "es") > sqrt(-1) [1] NaN Warnmeldung: In sqrt(-1) : NaNs wurden erzeugt ## try resetting to blank > Sys.setenv(LANGUAGE = "") > sqrt(-1) [1] NaN Warnmeldung: In sqrt(-1) : NaNs wurden erzeugt ## or back to English explicitly? > Sys.setenv(LANGUAGE = "en") > sqrt(-1) [1] NaN Warnmeldung: In sqrt(-1) : NaNs wurden erzeugt >
Dirk Eddelbuettel
2023-Jun-26 13:38 UTC
[Rd] restoring LANGUAGE env variable within an R session
Ben, POSIX level / glibc level variables are set at process start and AGAIK cannot really be altered after start. They clearly work when set _before_ calling sqrt(-1): $ LANGUAGE=es Rscript -e 'sqrt(-1)' [1] NaN Warning message: In sqrt(-1) : Se han producido NaNs $ LANGUAGE=de Rscript -e 'sqrt(-1)' [1] NaN Warnmeldung: In sqrt(-1) : NaNs wurden erzeugt $ I think the `callr` package can help you with this use from with R by effectively spawning a new process for you. Or, lower-level, you can call `system()` or `system2()` yourself and take care of the setup. Cheers, Dirk -- dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Sebastian Meyer
2023-Jun-26 14:02 UTC
[Rd] restoring LANGUAGE env variable within an R session
Translated strings are cached. I'd recommend to use the ? New partly experimental Sys.setLanguage() utility, solving the main problem of PR#18055. introduced in R 4.2.0. Best, Sebastian Meyer Am 26.06.23 um 15:15 schrieb Ben Bolker:> I was playing around with the setting of the LANGUAGE variable and am > wondering whether I'm missing something obvious about resetting the > value to its original state once it's been set. I seem to be able to > reset the language for warnings/errors once, but not to change it a > second time (or reset it) once it's been set ... ?? > > ## default (no LANGUAGE set, English locale) > > sqrt(-1) > [1] NaN > Warning message: > In sqrt(-1) : NaNs produced > ## no complaints, doesn't change (as expected) > > Sys.setenv(LANGUAGE = "en") > > sqrt(-1) > [1] NaN > Warning message: > In sqrt(-1) : NaNs produced > > ## change to German > > Sys.setenv(LANGUAGE = "de") > > sqrt(-1) > [1] NaN > Warnmeldung: > In sqrt(-1) : NaNs wurden erzeugt > > ## try to change to Spanish - no luck > ## (this does work in a clean session) > > > Sys.setenv(LANGUAGE = "es") > > sqrt(-1) > [1] NaN > Warnmeldung: > In sqrt(-1) : NaNs wurden erzeugt > > ## try resetting to blank > > Sys.setenv(LANGUAGE = "") > > sqrt(-1) > [1] NaN > Warnmeldung: > In sqrt(-1) : NaNs wurden erzeugt > > ## or back to English explicitly? > > Sys.setenv(LANGUAGE = "en") > > sqrt(-1) > [1] NaN > Warnmeldung: > In sqrt(-1) : NaNs wurden erzeugt > > > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel