I am trying to use RMarkdown to have python and R integrated together in one document.
The objects that I created in R are usable in python, and vice versa, when I use the RMarkdown in Rstudio. But when I knit it to PDF, following behaviour is observed:
Python code:
x = ‘hello’
R code:
py$x
If I run this without knitting, it returns the ‘hello’ in the console. But when I knit it to PDF, I can see the output to be ##NULL
Did you try to use quarto instead of RMarkdown for multilanguage projects? Quarto should be somewhat more versatile if you incorporate Python as well as R in your documents.
It is highly likely that these settings interfered with each other creating erroneous results.
The reason I modified the settings in the first place was that I wasn't able to call R objects in python (exactly the opposite of my current problem), for which some answers online suggested that setting eval = TRUE and cache = TRUE can do the job.
However, now everything seems to work just fine even with the stock settings.
This happens very often, that is why asking programming related questions with a reprex is such a good idea.
I'm glad you found a solution to your problem. Now to close the loop, if your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: