←back to thread

Big Book of R

(www.bigbookofr.com)
288 points sebg | 6 comments | | HN request time: 0.281s | source | bottom
1. kingkongjaffa ◴[] No.43647159[source]
What is the best way to integrate some R code with a python backend?

I’ve been tempted to port to python, but some of the stats libraries have no good counterparts, so, is there a ergonomic way to do this?

replies(5): >>43647179 #>>43647450 #>>43647806 #>>43647807 #>>43648782 #
2. jmalicki ◴[] No.43647179[source]
Do you dislike rpy? I've found it to be pretty easy to use.
3. bachmeier ◴[] No.43647450[source]
Not sure what you mean by "python backend". If you mean calling R from Python, rpy2 mentioned in the other comment works well. If you mean the other direction, RStudio has this all built in. This is probably the best place to start: https://rstudio.github.io/reticulate/articles/calling_python...
4. jjr8 ◴[] No.43647806[source]
There is also https://www.rplumber.io/, which lets you turn R functions into REST APIs. Calling R from Python this way will not be as flexible as using rpy2, but it keeps R in its own process, which can be advantageous if you have certain concerns relating to threading or stability. Also, if you're running on Windows, rpy2 is not officially supported and can be hard to get working.
5. huijzer ◴[] No.43647807[source]
CSV is generally the answer. Unless you need superb performance which generally is not the case.
6. malshe ◴[] No.43648782[source]
One of my students codes exclusively in Python. But in most cases newer econometrics methods are implemented in R first. So he just uses rpy2 to call R from his Python code. It works great. For example, recently he performed Bayesian synthetic control using the R code shared by the authors. It required stan backend but everything worked.