
PyThor- Python meets R - nipun_batra
http://nipunbatra.github.io/2016/01/pythor/
======
spot
Beaker Notebook provides a different model for working in Python and R.
Instead of wrapping one language in the other, you get a notebook where cells
can be either Python or R, fully native, and they can communicate with a
shared object. The result is much simpler and more natural IMO:
[https://pub.beakernotebook.com/#/publications/56648fcc-2e8e-...](https://pub.beakernotebook.com/#/publications/56648fcc-2e8e-41a6-aa4a-1249ee39023c?fullscreen=true)

Beaker has a feature "autotranslation" that converts the data between R,
Python, JavaScript, Julia, Scala, Clojure, and many other languages,
completely automatically. Learn more at
[http://BeakerNotebook.com](http://BeakerNotebook.com)

~~~
baldfat
Jupyter Notebooks (Formerly IPython Notebooks)
[http://jupyter.org/](http://jupyter.org/) is kernel agnostic and can work
with all the other languages also. I use it for R and Python myself. (For data
work I still prefer RStudio or Python's Rodeo)

Breaker uses the same jkernel as IPython and backend of Jupyter.

~~~
spot
that's right, but Jupyter notebooks have just one language each, they don't
facilitate polyglot programming.

~~~
captaindiego
Their are some "cell magics" for running different languages in individual
blocks in a Jupyter notebook. I gave it a try in passing with javascript a
while back and I remember there was a way to share variables through as well.

You can see the available magics here: [https://ipython.org/ipython-
doc/3/interactive/magics.html#ce...](https://ipython.org/ipython-
doc/3/interactive/magics.html#cellmagic-javascript)

Unfortunately it looks like there is none for R or Julia, but perhaps they are
installed by those specific packages, or their is some other way I don't know
of.

~~~
IndianAstronaut
Cell magics are exactly what I was looking for. Much easier to do some data
cleanup stuff in Python and move stats heavy stuff to R.

~~~
baldfat
RMagic for R and Python in Jupyter
[https://www.youtube.com/watch?v=StX_F_kq_C0](https://www.youtube.com/watch?v=StX_F_kq_C0)

~~~
IndianAstronaut
Good video. One thing I am looking to do is call Python from an R notebook,
but that doesn't seem to be happening with the magic functions.

------
phillipamann
I thought this was interesting but the resulting code was so ugly and awkward
that I would refrain from using it. I would just prototype in R and convert to
Python rather than using both in this sort of Frankenstein way.

~~~
baldfat
Just as a point of interest: Why would you convert a R program into a Python
program? I can't think of any benefit in terms of speed or reporting?

~~~
huac
Speed and scale (and reporting too, I guess) are very important considerations
for data analysis.

~~~
baldfat
But I wouldn't see Python as being speedier or better at scale and certainly
not reporting. What are your speed up and scale advantages in Python over R.
(Seriously interested)

Going R to Clojure or Julia seems like a gain but Python.

~~~
phillipamann
Sorry for delay. I think it's just better interoperability with many other
systems. R has very hacked on interoperability in my opinion but I am not an
expert.

------
amelius
I just can't wrap my head around R. I'd love it if there was an automatic
translator from R to Python. Even though the Python code would be more
cluttered, it would probably be more easy to read :)

~~~
baldfat
R has a lot of choices. I find that the Hadley Universe of libraries of
ggplot2, ggvis, dplyr, tidyr, stringr, readr and others with the piping of %>%
to be the easiest code for reading and getting things done. R has been
transformed in the last 5 years but still gets a bad rap which I don't feel it
deserves.

R is really more a functional language which most people don't recognize and
when they learn the standard core of R with Lisp inspired ideas it really
throws them for a loop. I ended up learning Racket (after trying to teach
myself Haskell 3 times) and I can say I now "get it," but using the new
libraries has really made that point mute.

I love R and am excited to see all the support from Microsoft and other large
companies jumping on board.

This does look like a decent way to move to Python though. If someone was to
do that I hope they use Rodeo IDE.

~~~
nipun_batra
I'll second that R is really awesome! Being a computer scientist, it opens up
for me a lot of statistical packages.

~~~
s_q_b
R is the only real game in town for free software for scientific computing
these days.

From a political perspective R was in the right place at the right time. It
was a decent high level language that could handle matrix processing
gracefully. Scipy/Numpy weren't ready for production yet. The others were
Matlab, SAS, and Stata, all of which R makes look like APL.

I'm glad the field has a more healthy open source landscape with worthy
competitors in the form of Julia and Numpy/Scipy.

R's biggest sin is failure to force people to use functional paradigms by
providing juuuust enough imperative sugar to make average Joe programmer feel
at home. _R is a functional language,_ and that's the principle under which is
should be taught.

That said, R also has a large number of main technical strengths:

1\. Fast basic statistics within the REPL so you can test hunches quickly.

2\. Cutting edge algorithms that often aren't implemented anywhere else.

3\. Hugely strong engineering packages for civil, environmental, defense,
aerospace and basically any IRL engineering field you can think of.

R comes free, with these advantages and many more for the average lab tech.

~~~
semi-extrinsic
> R is the only real game in town for free software for scientific computing
> these days.

You have a very very narrow definition of scientific computing, excluding a
huge part of the field, i.e. anything written in C, C++ or Fortran. And I've
never seen people in aerospace or civil engineering use R, it seems to be
mostly popular in statistics heavy, "softer" fields such as biology or
economics.

Edit: to give some examples of what I mean: show me a (molecular
dynamics|computational fluid dynamics|finite element method|Poisson
solver|magnetohydrodynamics solver|electrodynamics solver|general relativity
code|quantum many-body solver|lattice field theory code) written in R. I
haven't seen any.

~~~
baldfat
Just wanted to see a few. R has such a strong Fortran code base that I knew
that they needed to be in R somewhere.

Molecular Dynamic -
[https://cran.r-project.org/web/packages/bio3d/index.html](https://cran.r-project.org/web/packages/bio3d/index.html)

computational fluid dynamics -
[http://search.r-project.org/library/rjacobi/html/xinterp.htm...](http://search.r-project.org/library/rjacobi/html/xinterp.html)

finite element method -
[https://cran.r-project.org/web/packages/RTriangle/RTriangle....](https://cran.r-project.org/web/packages/RTriangle/RTriangle.pdf)

Poisson -
[https://cran.r-project.org/web/packages/isotone/isotone.pdf](https://cran.r-project.org/web/packages/isotone/isotone.pdf)

~~~
semi-extrinsic
None of those are actually simulation codes. The first and third are pre- and
post-processing tools. The second is an interpolation tool. The fourth uses
Poisson distributions, which is very different from solving the Poisson
equation.

~~~
s_q_b
We just have a mismatch in the term "scientific programming" based on our
perspectives. You seem like you're in the harder sciences in academia, while
I'm in data science in industry.

I'll certainly cede the point that there's a great deal of important
scientific code in many languages that can't be accessed from R.

~~~
semi-extrinsic
>We just have a mismatch in the term "scientific programming" based on our
perspectives.

Yes, exactly this.

------
mikeskim
it is probably easier to just wrap R functions as a subprocess in python. you
would have to write some R code to do this which might involve writing to a
flat file. i do this all the time in R wrapping up something like rgf and
calling from within R. i have wrapped up python and called it from R using
system. the same idea works for python as well. you could probably write some
kind of general wrapper that would work for most of R's ML type functions.

