Rgui never processes ~/.Renviron

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Rgui never processes ~/.Renviron

Henrik Bengtsson-5
ISSUE:
It looks like Rgui.exe never processes ~/.Renviron - only ./.Renviron.

REPRODUCIBLE EXAMPLE:
On Windows, create the following ~/.Renviron and ~/.Rprofile files:

C:\Users\alice> Rscript -e "cat('FOO=123\n', file='~/.Renviron')"
C:\Users\alice> Rscript -e "cat('print(Sys.getenv(\'FOO\'))',
file='~/.Rprofile')"

and launch Rgui (from a folder other that ~):
C:\Users\alice> Rgui

and you'll see that FOO is reported as "" (empty), whereas with R or
Rscript, it is reported as "123".


TROUBLESHOOTING:
From code inspection
(<https://github.com/wch/r-source/blob/1658c8491e9cdc6d2fe61603ed23ae56232b6727/src/main/Renviron.c#L298-L301>):

#ifdef Win32
  {
    char buf[1024]; /* MAX_PATH is less than this */
    /* R_USER is not necessarily set yet, so we have to work harder */
    s = getenv("R_USER");
    if(!s) s = getenv("HOME");
    if(!s) return;
    snprintf(buf, 1024, "%s/.Renviron", s);
    s = buf;
  }
#endif

I think it happens because neither R_USER nor HOME is set when the
Rgui startup process calls process_user_Renviron().

WORKAROUND:
Setting R_USER or HOME prior to calling Rgui will cause Rgui to
process ~/.Renviron, e.g.

C:\User\alice> set R_USER=%UserProfile%\Documents
C:\User\alice> Rgui

The background for finding this is R-help thread '[R] tempdir() does
not respect TMPDIR' on 2020-08-29
(https://stat.ethz.ch/pipermail/r-help/2020-August/468573.html).

/Henrik

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rgui never processes ~/.Renviron

Dirk Eddelbuettel

On 2 September 2020 at 23:38, Henrik Bengtsson wrote:
| WORKAROUND:
| Setting R_USER or HOME prior to calling Rgui will cause Rgui to
| process ~/.Renviron, e.g.

AFAICR one _always_ had to manually set $HOME on Windows as the convention of
having it comes from the some other OSs and is not native.

In short I don't think this is new. A quick Google search seems to confirm
this with a SuperUser answer from 2013:

https://superuser.com/questions/607105/is-the-home-environment-variable-normally-set-in-windows

Dirk

--
https://dirk.eddelbuettel.com | @eddelbuettel | [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Rgui never processes ~/.Renviron

Henrik Bengtsson-5
I've "moved" this to
https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17919 to make sure
it's tracked.  /Henrik

On Thu, Sep 3, 2020 at 7:25 AM Dirk Eddelbuettel <[hidden email]> wrote:

>
>
> On 2 September 2020 at 23:38, Henrik Bengtsson wrote:
> | WORKAROUND:
> | Setting R_USER or HOME prior to calling Rgui will cause Rgui to
> | process ~/.Renviron, e.g.
>
> AFAICR one _always_ had to manually set $HOME on Windows as the convention of
> having it comes from the some other OSs and is not native.
>
> In short I don't think this is new. A quick Google search seems to confirm
> this with a SuperUser answer from 2013:
>
> https://superuser.com/questions/607105/is-the-home-environment-variable-normally-set-in-windows
>
> Dirk
>
> --
> https://dirk.eddelbuettel.com | @eddelbuettel | [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel