Run bash from R

First we set up the bash engine.

library(knitr)
library(runr)
b = proc_bash()
b$start()
knit_engines$set(bash = function(options) {
    knitr:::wrap(b$exec(options$code), options)
})

Test echo:

x=asdfqwer
echo $x
## asdfqwer

Works! A next chunk:

echo "hello, $x, $x and $x"
echo ${#x}
## hello, asdfqwer, asdfqwer and asdfqwer
## 8
echo $x | sed s/asdf/1234/
## 1234qwer

Do not forget to shut it down in the end.

b$stop()