Why is the variable defined by the rmd file of the python script not displayed in the environment in the upper right corner?

I am learning python recently. I converted the ipynb format file to the rmakddown file, but when I run it, the variable I define cannot be displayed in the variable in the upper right corner of sutdio. Is it a setting problem or the setting of the software itself?

That is normal behavior. I believe when you knit a Rmd file, it is run in is own environment and the variables are not stored in the Global Environment. The Environment pane on the right is displaying the Global Environment.

Thank you very much for your answer, if I edit Rmarkdown in R language, the variables will be stored, do you know of a way to make PYTHON's scripts also stored? Because sometimes I need to share some variables and data between the two languages.

I misunderstood your question but now I see your problem. I have not used Python in Rstudio, so I cannot help much. I did find the article linked below. If you look near the end of that, there is a section labeled Environment Pane. In the image, you can see that the drop down list just above the header Name says Python. In the image in your last post it says Global Environment. Can you select Python from that list?

To access the python values, I found a StackOverflow thrad that may help. It seems there is a list in R named py. If in Python you set

a = 1

in R you can access that with

py$a

Similarly, in Python the R objects can be accessed with the r object

r.a

Keep in mind that I am not a Python user in R, so my answers may be incorrect. I apologize for having misunderstood your original question and stepping into a thread where I cannot help as well as I would like to.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.