2
votes

We are using rmarkdown to produce a book on Python programming. Code chunk options like eval = TRUE and echo = TRUE can be used to show the nicely formatted code in the output, run it, and show the result within the text.

What would be useful, though, would be to be able to sometimes prepend the code with the Python >>> prompt, to indicate code typed in an interactive terminal.

Is there a way to insert the >>> prompt as a prefix?

1

1 Answers

4
votes

You can use the knitr chunk option prompt = TRUE after you set options(prompt = '>>> ') in a previous code chunk, e.g.

```{r include=FALSE}
options(prompt = '>>> ')
```


```{python, prompt=TRUE}
print("hello world")
```

And adding options(continue = '>>> ') will add the >>> prompt prefix for multiple lines.