One of the main reasons I strongly prefer R to Python is that RStudio is far better than all Python IDEs I have used. I usually use Spyder for my Python IDE, but it has a lot of shortcomings compared to RStudio.
RStudio has added some Python support, for example in Rmarkdown files, in the past. Recently I discovered the R package reticulate which is closely integrated with RStudio and lets you run Python code more easily in RStudio. This blog post gives a great overview of how it works with examples. I’m going to go through some of the highlights here to give it a test run.
Enhanced RMarkdown with Python chunks
R Markdown files have allowed Python before,
but now variables from these chunks can be accessed
in following chunks using py$<variable name>
.
Similarly, Python code can access R variables
using r.<variable name>
.
This is especially handy when you have certain tasks
or functions that are already coded in one language
but you want to use the results in the other.
Running a Python session in R
If you call reticulate::repl_python()
, a Python session begins
within the console.
Typing exit
will quit the session.
This doesn’t seem useful at first, but you can share variables between R and Python as shown above. Thus if you have code or libraries that you need in both R and Python, it should be easier to pass the data between them rather than writing the data to file and reading it back in.
Conclusion
Reticulate gives some cool capabilities for mixing R and Python. While this is useful when you have code in R and Python you want to mix, RStudio is not a replacement for a Python IDE, and likely won’t ever since it is focused on R. The lack of text highlighting or autosuggest for Python files in RStudio are two major deficiencies, both of which seem like easy problems to solve, though, so it isn’t too farfetched.