[R] Environment variable defined in .bashrc is not recognized by R

Rainer M Krug Rainer at krugs.de
Tue Apr 1 11:57:25 CEST 2014

Luca Cerone <luca.cerone at gmail.com> writes:

> Thanks,
> effectively I was using RStudio (on an Ubuntu 12.04 machine).
> Is there any other way to make the variable available to Rstudio?
> Now I have simply written the path manually, but I like the idea of
> having a system-wide variable :)

Check out 


and, specifically for Ubuntu:


If you need more: just google for
  login shell variable Ubuntu



> Thanks for your help, Rainer!
> On Tue, Apr 1, 2014 at 11:25 AM, Rainer M Krug <Rainer at krugs.de> wrote:
>> Luca Cerone <luca.cerone at gmail.com> writes:
>>> Dear all,
>>> in my .bashrc file I have set the environment variable R_HISTFILE like this:
>>>  export R_HISTFILE="$HOME/.Rhistory"
>>> I then use it in my .Rprofile to have R writing all the history in a
>>> single file, rather than on a per directory basis.
>>> However this doesn't work becaus R_HISTFILE is not recognized by R.
>> Which OS? How do you start R?
>> There is a difference between login shell (executed when you log in) and
>> non-log in (I thik interactive shell? don't know the actual
>> name). .baschrc is only executed after you are logged in and start the
>> shell. So when you start R from the shell, it should work - you can
>> check by
>>   echo $R_HISTFILE
>> which should show you the value of the variable.
>> If you are starting R the R gui (on Mac or RStudio) .bashrc is not
>> sourced. Checo online for the file which will be sourced by the login
>> shell - different between OS and distros.
>> Cheers,
>> Rainer
>>> If I type: Sys.getenv("R_HISTFILE")
>>> the output is: ""
>>> How can I get R recognizing environment variables?
>>> Best,
>>> Luca
>> --
>> Rainer M. Krug
>> email: Rainer<at>krugs<dot>de
>> PGP: 0x0F52F982

Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 494 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140401/4bc7d005/attachment-0002.bin>

More information about the R-help mailing list