[Rd] restoring LANGUAGE env variable within an R session

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Mon Jun 26 15:49:01 CEST 2023


   That's reasonable, but I'm wondering why it works the *first* time 
it's called in a session. Is this just undefined behaviour (so I 
shouldn't be surprised whatever happens)?  Again,

$ Rscript -e 'sqrt(-1); Sys.setenv(LANGUAGE="es"); sqrt(-1)'
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced
[1] NaN
Warning message:
In sqrt(-1) : Se han producido NaNs

   I should clarify that this really isn't that important for my 
workflow, it just seemed like an odd loose end.

Weirdly, I just discovered that Sys.setLanguage().  Don't know how it 
differs, but there's a bindtextdomain(NULL) call  there which may be the 
magic sauce ... ???

  sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced
 > Sys.setLanguage("de")
 > sqrt(-1)
[1] NaN
Warnmeldung:
In sqrt(-1) : NaNs wurden erzeugt
 > Sys.setLanguage("en")
 > sqrt(-1)
[1] NaN
Warning message:
In sqrt(-1) : NaNs produced



On 2023-06-26 9:38 a.m., Dirk Eddelbuettel wrote:
> 
> 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
> 

-- 
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
(Acting) Graduate chair, Mathematics & Statistics
 > E-mail is sent at my convenience; I don't expect replies outside of 
working hours.



More information about the R-devel mailing list