Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 539
Courvoisier Avatar asked Oct 24 '25 19:10

Courvoisier


1 Answers

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.

like image 72
Jabba Avatar answered Oct 26 '25 17:10

Jabba