New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem trying to source ~/.bashrc in bash chunk #1762
Comments
|
I'm surprised that |
|
I think this is because startup script are not loaded the same way when bash is use non-interactively. For this information, several solutions I tested
---
title: "test bash option"
output: html_document
---
```{bash}
echo $BASH_LOADED
```
Here are the results I got:
Sys.setenv(BASH_ENV="~/.bashrc")
knitr::knit("test.rmd")However, if you already have this env var set, it needs to be taken care of by appending I guess. If you pass the ```{bash, engine.opts="--login"}
<your code>
```or in a setup chunk knitr::opts_chunk$set(engine.opts = list(bash="--login"))it seems to work the same with Also, using knitr::opts_chunk$set(engine.opts = list(bash="-i"))and knitr::opts_chunk$set(engine.opts = list(bash="--init-file ~/.bash_profile -i"))also work for me. I tested on centos 7.4. Does any of the above works for you ? Do you have an error message from bash ? I'll continue my test with an alias, and not an environment variable.
|
|
I think at the end, this is maybe a matter of documentation about how the I am not sure knitr could improve this. We plan to add a generic engine to run any command easily for an engine. This could be a way to solve this kind of issue by writing your self the command the engine should use mor explicitly than passing options. I'll leave that open as a "better doc" needed about the different engines maybe including this one. |
I am trying to use some aliases within a bash chunk in my R notebook. These aliases are defined in my ~/.bashrc or ~/.bash_profile file. Using the standard {bash} engine it throws an error. It means that ~/.bashrc or ~/.bash_profile is not sourced at bash startup. I have then written an hook to force the sourcing in my setup chunk as follow:
I tested the resulting bash invocation in bash terminal:
bash --init-file ~/.bash_profile -i -c "alias ll"and generates the expected output. I have then inspected the source code for the engine function and I suspect there is a typo messing with engine.opts setting.In my opinion the hook is not necessary, because the bash invocation sources the ~/.bashrc or ~/.bash_profile automatically. Is it that rstudio/knitr runs the bash chunk as different user? I tried to run
whoamiinside a chunk and my username is returned. So, why the ~/.bashrc or ~/.bash_profile file is not sourced?EDIT: setting
knitr::opts_chunk$set(engine.opts = list(bash="--init-file ~/.bash_profile -i"))in setup chunks does not work either.The text was updated successfully, but these errors were encountered: