How to make a python variable persist between chunk in a markdown notebook?
How to make a python variable persist between chunk in a markdown notebook? Variable are not retained from one chunk to the next in notebook mode, but they are retained when knitting the markdown document to html. I made a sample document available as a gist called pythonvariables.Rmd, the content of this file is: --- title: "R Notebook" output: html_document: df_print: paged --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(reticulate) ``` ```{python} x = 1 ``` ```{python} print(x) ``` ```{r} print(py$x) ``` In Rstudio version 1.1.453, in notebook mode, when running one chunk after the other, the output of the print(x) python chunk is: print(x) Traceback (most recent call last): File "C:UsersrougipaAppDataLocalTemp2RtmpQFW3Rjchunk-code-1d44920f50.txt", line 1, in <module> print(x) NameError: name 'x' is not defined However the issue doesn't appear when the Rmd is compiled to html. The output of the print(x) p...