Python chunk echos in r-markdown, but not r-notebook

413 Views Asked by At

I like to take notes inside of r-notebooks and have recently been trying to incorporate python code chunks into some of my documents. I have no problems executing python chunks and displaying the output, but I get different behavior depending on whether I'm using an R-notebook or an R-markdown document. While R-markdown will echo the python code and display the output, R-notebook will only display the output. I have tried explicitly stating echo=T in the chunk, bit it does not change the outcome. Any thoughts on how to get the appropriate behavior in R-notebooks?

EDIT: Will also add that this behavior in notebooks only appears to happen when the code chunk has a printed output. A chunk that does not print will echo code correctly.

Below is an example:

R-notebook example

---
title: "R Notebook"
output: html_notebook
---

Example R-notebook

```{r setup, include=FALSE}
library(knitr)
library(reticulate)
knitr::knit_engines$set(python = reticulate::eng_python)
```
```{python}
print("Hello world")
```

Output of R-notebook


R-markdown example

---
title: "R Notebook"
output: html_document
---

Example R-notebook

```{r setup, include=FALSE}
library(knitr)
library(reticulate)
knitr::knit_engines$set(python = reticulate::eng_python)
```
```{python}
print("Hello world")
```

Output of R-markdown

0

There are 0 best solutions below