Is it possible to share variables between pieces of a cube using engine = "bash"?

Something like this, but this does not work:

```{r examples, engine="bash"} export EXAMPLES="example/path" ``` ```{r example1, engine="bash"} echo $EXAMPLES ``` 

This works, however:

 ```{r examples2, engine="bash"} export EXAMPLES="example/path" echo $EXAMPLES ``` 
+7
source share
1 answer

This is a great question! This is what I really want to achieve, but don’t know how to do it (I appreciate if anyone can help me). This is useful not only for bash , but for all other knitr engines like python , ruby etc. The reason this does not work at the moment is that knitr runs the code through system('engine -arg code') , that is, for each piece of code, a new mechanism session is opened, so all the pieces are executed mainly in different processes.

Ideally, I need an engine that opens a session and continues to listen to the new code, but I'm not sure if this is possible at all. AFAIK, the only way to exchange variables is to write them to files, which is clearly inconvenient.

+4
source

All Articles