I have greatly enjoyed how easy it is to switch between bash
and r
commands while using Rstudio Notebook/RMarkdown.
However I have struggled because the path that is searched when I run a bash
command from inside a Rstudio Notebook
bash
echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Library/TeX/texbin
Is different than my path when I execute a command from the terminal (whether inside Rstudio or directly from my computer).
bash
echo $PATH
/home/greg/bin:/home/greg/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
Can someone please point me to a reference where I can learn how the path for Rstudio Notebook is created and where I can edit it.
Thanks
This is a problem, and I'm hoping for an answer myself. Just posted a similar question.
I believe the issue here is that bash
chunks are not run as though the bash
shell is a login shell, so init scripts are not sourced. This implies any custom settings for the PATH
are not set in these chunks.
1 Like
Thanks @kevinushey! Do you have any suggestions on how to best modify the PATH accessible via a bash
command through RMarkdown so it is permanently updated?
For example, if I run the following in a single RMarkdown code block my $PATH is correctly appended with the new location.
# path updated
echo $PATH
export PATH=$PATH:/Users/botwing/my_new_path
echo $PATH
But if I try to run the following in two RMarkdown code-blocks, my $PATH is not updated.
echo $PATH
export PATH=$PATH:/Users/botwing/my_new_path
Then...
# not updated
echo $PATH
Any ideas on how to permanently, or at least per RStudio session, to modify the accessible $PATH?
Thanks,
Greg
I think you can use engine.opts
to force the shell to behave like a login shell, e.g.
```{bash, engine.opts='-l'}
echo hello
```
I'm not sure if there's a way to set this option more globally, though. (You could perhaps define your own custom bash
engine chunk that enforces -l
or similar?)
3 Likes
Thanks @kevinushey! That solves my problem and is easy to add to my bash blocks! Appreciate your help.