[R-SIG-Mac] Shell used within system()

Simon Urbanek simon.urbanek at r-project.org
Sun Jul 6 13:03:59 CEST 2014


Marc,

you omitted important details, but I think the short answer is see Mac FAQ 10.13.

The long answer is that it has nothing to do with the shell. If you run R on the command line then it inherits all your setting - including all variables that you set in your config files.

If you run the R.app Mac GUI then there is *no* login shell involved since it's an application run through launch services, so none of user login config files are processed. When you run system() - it is not running a login shell, but just regular shell hence the config files are again irrelevant (this is also true for R in Terminal, but there you already inherit the settings from the login shell). Also if you look at sh --version you will notice that it is already bash.

Cheers,
Simon

On Jul 6, 2014, at 8:02 AM, Marc Girondot <marc_grt at yahoo.fr> wrote:

> Hi,
> 
> I try to automatize some commands normally used in terminal that I would like to run in R.
> 
> However, the same command xxx in terminal and in system("xxx") does not produce the same result.
> 
> It seems related to the shell used and the variables of the shell.
> 
> For example, in terminal:
> Marc-Girondot-MBA:Chlorophyle marc$ echo $PATH
> /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/ncl-6.2.0/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/GDAL.framework/Programs:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin
> 
> whereas in R:
> > system("echo $PATH")
> /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin:/opt/local/bin
> 
> The shell used in terminal is
> Marc-Girondot-MBA:Chlorophyle marc$ echo $SHELL
> /bin/bash
> Marc-Girondot-MBA:Chlorophyle marc$ echo $0
> -bash
> 
> whereas in R, it is sh:
> > system("echo $0")
> sh
> 
> And this sh does not read my configuration files. I have tried to modifiy the ~/.profile or ~/.login but system("echo $PATH") does not change.
> 
> My question is then:
> is it possible to change the default shell used by system ? I have tried:
> system("/bin/bash\necho $0\necho $PATH")
> 
> but R becomes unresponsive...
> 
> or where is the configuration file for sh run by R ?
> 
> Thanks a lot
> 
> Marc
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
> 



More information about the R-SIG-Mac mailing list