I have to run a shell script inside R. I've considered using R's system
function.
However, my script involves source activate
and other commands that are not available in /bin/sh shell. Is there a way I can use /bin/bash instead?
Thanks!
I have to run a shell script inside R. I've considered using R's system
function.
However, my script involves source activate
and other commands that are not available in /bin/sh shell. Is there a way I can use /bin/bash instead?
Thanks!
Invoke
/bin/bash
, and pass the commands via-c
option in one of the following ways:If you only want to run a Bash file, supply it with a shebang, e.g.:
and call it by passing script's path to the
system
function:It is implied that the current user/group has sufficient permissions to execute the script.
Rationale
Previously I suggested to set the
SHELL
environment variable. But it probably won't work, since the implementation of thesystem
function in R calls the C function with the same name (seesrc/main/sysutils.c
):And
(see
man 3 system
)Thus, you should invoke
/bin/bash
, and pass the script body via the-c
option.Testing
Let's list the top-level directories in
/tmp
using the Bash-specificmapfile
:test.R
test.sh
Sample Output
Original Answer
Try to set the
SHELL
environment variable:Then the commands passed to
system
orsystem2
functions should be invoked using the specified shell.