Courvoisier
Courvoisier

Reputation: 983

Rmarkdown - python inline code in Rmarkdown

I am using Rmarkdown with python. What is the equivalent of the R inline code for python? Example, in https://rmarkdown.rstudio.com/lesson-4.html I can do

``r x`

to display the value of x in the text. but If I do

``python x`

I just get the text python x

Upvotes: 4

Views: 1368

Answers (2)

Jabba
Jabba

Reputation: 20614

With this workaround, it's possible:

```{r setup, include=FALSE}
library(reticulate)
```
 
```{python include=FALSE}
result = 1 + 1
```
 
1 + 1 = `r py$result`    # 1 + 1 = 2

Where py$result means: take the value of the Python variable called result.

Upvotes: 4

stefan
stefan

Reputation: 123808

Not sure whether this is possible. All examples I have found use R inline code like so `r py$x` to achieve that. See e.g. the rmarkdown cookbook.

Upvotes: 3

Related Questions