R + Python in IDE

Any chance there will be expanded Python support in a future version of RStudio? I know that the editor has support (awesome) and Python scripts run in the R console with system()after clicking on "Run Script" (also awesome), but it would be amazing to have all the tools we have for R in RStudio available for Python too. Then RStudio would be a real 'data science' IDE (Python ones suck). Pretty please? :nerd_face:


From community.rstudio.com moderators:

On March 26 2018 RStudio announced "reticulate: R interface to Python"
Learn more about reticulate at its website; R Interface to Python or via github.com/rstudio/reticulate.

28 Likes

I can only second that!
To add to that, I find the new feather format already a big plus in easily converting data from one platform to the other. It would be however fantastic to have some interface library that would make interactions between R and Python more natural, such that tibbles could be passed as an argument to some python code within the same script, where they would be transformed into a pandas frame. Then, some specialized ML algorithm could run, return a pandas object which is then translated into a tibble to be processed by some neat R functionality, say for visualisation. This way the best of two worlds could be used without having to translate and thereby duplicate all the packages.

8 Likes

I, too, look forward to that day. I really don't know how the Python guys do it without an interactive IDE that has REPL capabilities.

The closest things for R users are: Yhat Rodeo, SublimeText, and Sypder.

  • Yhat has the looks of RStudio, that's about it. It does not even have the basic REPL capabilities. For example, if you send a script over to console, your can't recall it with an up arrow, only the codes you typed in console.

  • SublimeText is a little better, keybinding requires understanding of JSON, not hard. You must invoke Python kernel at startup every time, because it's for general purpose, not just Python.

  • Spyder looks like in early development stage still. You need to launch it from terminal. If you have Anaconda installed, you can open it up, and launch Spyder there.

3 Likes

In RStudio 1.1, you can use RStudio as a Python REPL. There's not support for it specifically, but since we now have a terminal that you can send lines to, and you can run Python in that terminal, it's surprisingly usable.

image

(h/t @GaryR for screenshot)

It's never been our goal to make RStudio a fully multilingual IDE, but we've improved Python support in every release (check out the integration with the reticulate package if you haven't already), and have plans for more Python support in 1.2. Stay tuned!

28 Likes

Yeah, I tried all those, and Atom too. Nothing beats RStudio for R-related things so I keep coming back to it (and love it). So I'd like to keep the Python stuff I do in the same place if possible!

3 Likes

You can run Python in RMarkdown code chunks at the moment if you change the header to

```{python}

There's currently no code completion, which makes it impractical for writing much, but for running something quick it's handy. Same for SQL, which can actually be more useful:

drill

16 Likes

wow, that's so awesome! I will need to upgrade and try it out.

Does it also include syntax highlighting, keybinding, autocomplete, and the other cool features?

I just tried to create an R presentation for my python stuff but unfortunately python chunks do not have highlighting support. The rendered python code chunks are not colored. Is there someone out there how to do this? :slight_smile: At least, I wish to create educational material for python by using RMarkdown and presentations.

Is this for RStudio 1.1?

RStudio 1.0 or higher, per the docs

I think you may find Apache Zepplin, Jupyter, or JupyterLab interesting and/or useful.

JupyterLab has a lot of potential, but is still fairly new. Here is a video from PyData DC 2016

1 Like

Wow, thanks I wasn't aware of the possibility to run Python scripts from RStudio. However, I would really love to use a single IDE for both the languages...

3 Likes

I'm more of a vim and console guy myself, but have you tried the Geany IDE which supports multiple languages including R and Python? I presume it's support for each language is at a more basic level than a dedicated IDE like RStudio offers though.

1 Like

That is awesome! :+1: Thank you for that! So far for Python I use mostly Rodeo or PyCharm, but it will be great to have both in RStudio.

Btw. would you consider also support for Julia in near future? (I mean... Jupyter/IPython as data science platform is great, but to have it all in one place and in advanced IDE like RStudio... yes, please :sunglasses:)

+Tip/Food for thought: IMHO with support for Python, Julia (or f.e. also Scala) it would be also great "positioning" for RStudio as the ultimate Data Science IDE & maybe it could even bring communities together (f.e. those R vs. Python "wars" are crazy...) and we could focus more on solving problems and not on "which language is better" flame wars. :thinking:

3 Likes

The python chunks in Rmarkdown are not connected, right? This makes working on longer reports a bit of a hassle.
This feature for creating dynamic reports easily is currently somewhat lacking in python. Took me ages to find something similar to the kable command.

Thanks Michael, I'm using Jupyter to create slides for python course material at the moment but it's not as productive as R presentations. It can run python code chunks (they are also connected @akingl) but it does not suppport highlighting of python code. I think/hope a little effort can make that Rstudio/R presentation best and single tool to create presentations for programming language.

Negative sides of Jupyter Notebook in terms of HTML5 slides:
1- You have to run another browser based server to create notebooks. (in RStudio you don't have to)
2- You have to work on a browser based interface. (I wish to work on a text editor, why would you want to click chunks and add code or markdown seperately?)
3- You have to convert notebook to slides by another server based approach by jupyter nbconvert tool.
4- Also it's required extra steps to upload your presentation to github/pages.

PS: I don't know much about Apache Zepplin and JupyterLab.

That R variable assignment in sql code chunk is awsome!

2 Likes

@isezen, I agree having a single IDE for all development would be great, and RStudio is so wonderful that it would be a top candidate for this. That said, it doesn't sound like RStudio will be a fully multilingual IDE:

If you're looking for a desktop based approach that has a Jupyter Notebook feel, then I recommend checking out nteract.

1 Like

PyCharm blog is saying it will have something look like RStudio.

Yes, I don't see why RStudio shouldn't support Python.

6 Likes

To answer more precisely on the request of @RobertMyles : take a look at the R Package PythonInR(available both on CRAN and GitHub).

It will allow you to submit a Python code to a Python Engine backend, and get the result.

Here, some of the most notable features :

  • calling Python is as simple as calling a R Function
  • arguments and return values are R objects
  • prints are sent back to RStudio Console
  • on the fly (bi-directional) conversion between R native data types & NumPy / Pandas ones (dataframes, vectors)
  • you can submit a code in a form of a Python string (possibly templated)
  • or a file script, a module, ...
  • import a Python function as a R function
  • PythonInR covers the entire Python FFI API (completeness)
  • ...

It's so usefull in my everyday work, that I pray it will be maintained asis, open-source, never forked and everlasted on CRAN.

And don't forget that RStudio is very handy to edit Python files.

Enjoy it.

8 Likes