How to persist bash variables from one code chunck to another in Rmarkdown?

Viewed 85

I have the following rmarkdown example, where I want to persist the shell variables from one code chunk to another. It seems it runs a new shell for each chuck. Is it possible to get a single shell session for the whole document?

---
title: "Test"
output:
  pdf_document:
    toc: true
    highlight: zenburn
  html_document:
    toc: true
    theme: united
---

text

```{bash, engine.opts='-l'}
TEST="12345"
echo $TEST
```

more text

```{bash, engine.opts='-l'}
echo $TEST
```

Compiling with

rmarkdown::render('test.Rmd', 'html_document')

and the result is displayed below

enter image description here

0 Answers
Related