How can you run {reticulate} Python code interactively in a {knitr} notebook?

First, I have to say that that I'm a huge fan of @jjallaire et al.'s {reticulate}. It has replaced {rpython} and friends in almost all of my code.

The latest announcement on reticulate, highlighting its use with @yihui's {knitr}, is much more than I would have hoped for last year when @jonathan said "it’s never been our goal to make RStudio a fully multilingual IDE".

All of that being said, I'm bumping up against an edge that I can't quite figure out and could use some guidance.

I'm able to get things to work as I expect with html_document as the output if I knit my results. However, when I run the chunks one at a time from the IDE then it looks like reticulate::eng_python() isn't getting used. Specifically, if I specify a different version of Python for {reticulate} to use that isn't reflected. Regardless of whether I specify a different version of Python, the results from Python calculations aren't available under py$.

Is there something I'm doing wrong, some magic step I'm missing, or is it just silly to expect this to work that way in the first place?

Details are here: https://rstudio.github.io/reticulate/articles/rstudio_ide.html

In short, you need to install the daily build of RStudio from https://dailies.rstudio.com

3 Likes

Just to make this a little clearer: by this we mean that we don't envision RStudio as a generic, language-agnostic IDE; it will always be first and foremost a workbench for R. However, many people use other languages in combination with R in their workflows and we're very much interested in bringing auxiliary support for those languages to RStudio.

4 Likes