My personal experience has been with Rpy
, not Rpy2
. I used it for a while, but dropped it in favor of using system
commands. A typical case for me was running a FORTRAN model using Python scripts, and post-processing with R. In my experience the easiest solution was to create a command line tool using R, which is quite straightforward (at least under Linux). The command line tool could be executed in the root of the model run, and the script would produce a set of R objects and plots in an Routput
directory. The advantage of disconnecting R and Python in this way was that I could easily debug the R code separate from the Python code.
I think Rpy
really shines when a lot of back and forth communication between R and Python is needed. But if the functionality is nicely separable, and the overhead of disk i/o is not too bad, I would stick to system
calls. See ?system
for more information regarding system calls, and Rscript
for running R scripts as a command line tool.
Regarding your wish to write R code in a Python way, this is not possible as all the solutions require you to write R code in R syntax. For Rpy
this means R syntax, but a little different (no .
for example). I agree with @gauden that there is no shortcut in using R through Rpy
.
reticulate
to the list cran.r-project.org/web/packages/reticulate/vignettes/… – Justiceship