I want to execute bash statements in an RStudio .rmd file as follows.
```{bash}
ls
```
At first RStudio would just hang showing the red button beside the code chunk. I figured out that the OpenSSH version of bash was opening a shell window, so by adjusting the windows system path, I got the ...\Git\bin\bash.exe
version to execute.
Then I got the following error in red:
bash: C:\Users\{me}\AppData\Local\Temp\RtmpmEF1jM\chunk-code3cb46c6027b3.: No such file or directory
This happens with each of the only four engines (sh, bash, perl and python) that appear to be executable on the Rmarkdown page (showing a little green triangle to the right of the chunk). This is less than the language examples described on this page for Python, SQL, Bash, Rcpp, Stan, JavaScript and CSS and much less than the 38 contained in the knitr::knit_engines
object.
Searching StackOverflow, I came across this short example showing how to write your own language engine. So I modified it to access the Git-Bash shell, and registered the function as follows:
eng_gitbash <- function( options ) { ... }
knitr::knit_engines$set( gitbash = eng_gitbash )
But then when I executed the chunk, {r, engine='gitbash'}
, I got this error.
'"C:\Users\{me}\AppData\Local\Temp\RtmpmEF1jM\chunk-code3cb476f93db0."' is not recognized as an internal or external command, operable program or batch file.
I have read though a lot of Yihui Xie's excellent documentation, but I can't seem to find how to test the eng_gitbash
function that I wrote. If someone could show me how the "options$engine can be directly used in command line to execute the code", I might be able to get my own version working.
Also as a general question, can someone point me to a description of the environmental requirements for a language engine 1)to be recognizable as executable by RStudio and 2)to be executed properly using Windows temp files.
Thanks, Sue