[R] In R, how do I execute a script that sets environment variables within the same shell session?

Duncan Murdoch murdoch.duncan at gmail.com
Wed May 23 02:06:32 CEST 2012


On 12-05-22 1:24 PM, Michael wrote:
> In R, how do I execute a script that sets environment variables within the
> same shell session?
>
> Hi all,
>
> Could you please shed some lights on how to do this?
>
> In a shell, I launched the R session.
>
> But then in R, I realized that some environment variables need to be set up.
>
> Of course I can use "Sys.setenv()"...
>
> But I have so many of them...
>
> And for some special reason, I have to first launch R and then run the
> script from within R to set up the environment variables...
>
> i.e.
>
> I cannot do the other way around, which is first execute the script in the
> shell,
>
> and then launch the R session(which is the usual sequenc of ordering)...
>
> So my question is:
>
> I have to launch R session first, and then run the scrip from within R.
>
> But if I naively use "shell" or "system", that's going to not affect the
> same shell that the R is using...
>
> I would like the R session to be able to access those "global" environment
> variables...
>
> How do I do that?

You already answered it.  Use Sys.setenv(). It will only affect the 
current process.

Duncan Murdoch



More information about the R-help mailing list