[R] sourcing a linux file with "system"

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Feb 26 12:24:31 CET 2011


And what do you think 'source' does?  Or system() does (check the help 
page)?

Hint: source is not an external command on Linux, but a builtin 
command of some shells (e.g. csh, bash), but not of sh -- in sh the 
equivalent is '.'.

On Sat, 26 Feb 2011, james.foadi at diamond.ac.uk wrote:

> Dear R community,

> I would like to source a file in my linux system to set a few 
> environment variables.

Hmm, how is that going to work?  That will set environment variables 
in the shell launched by system(), not for the R process.  The only 
way to set environment variables for the running R process is to call 
Sys.setenv.

> I have tried:
>
>> system("source /home/james/build//ccp4-6.1.13/include/ccp4.setup")
>
> and got:
>
> sh: source: not found
>
> In fact, using Sys.which("source") I get an empty string.
> How can I source that ccp4.setup file from within an R session?
>
> J
>
> Dr James Foadi PhD
> Membrane Protein Laboratory (MPL)
> Diamond Light Source Ltd
> Diamond House
> Harewell Science and Innovation Campus
> Chilton, Didcot
> Oxfordshire OX11 0DE
>
> Email    :  james.foadi at diamond.ac.uk
> Alt Email:  j.foadi at imperial.ac.uk
>
> Personal web page: http://www.jfoadi.me.uk
>
>
> -- 
> This e-mail and any attachments may contain confidential...{{dropped:8}}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list