News for hackers. Stuff that matters.
Re:Big Book of R by kingkongjaffa on Thursday April 10, 2025 @03:15PM (#43647159)
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?

Re:Big Book of R by bachmeier on Thursday April 10, 2025 @03:51PM (#43647450)
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...
Re:Big Book of R by jmalicki on Thursday April 10, 2025 @03:17PM (#43647179)
Do you dislike rpy? I've found it to be pretty easy to use.
Re:Big Book of R by jjr8 on Thursday April 10, 2025 @04:36PM (#43647806)
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.
Re:Big Book of R by huijzer on Thursday April 10, 2025 @04:36PM (#43647807)
CSV is generally the answer. Unless you need superb performance which generally is not the case.
Re:Big Book of R by malshe on Thursday April 10, 2025 @07:02PM (#43648782)
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.