Interoperate R with Python
Interoperate R with Python
from rchitect import * rcopy(reval("R.version"))
# install released version pip install -U rchitect # or the development version pip install -U git+https://github.com/randy3k/rchitect
Why another R interface when there is
rchitectis 100% python
rchitect is primarily used by
radian which is an alternate R console.
rpy2 was not an option because it requires compilations and who wants to compile!?
At stated above,
rpy2 requires tool chains to install which makes it not portable.
rchitect on the other hand is lightweight and portable.
rpy2 supports a large number of python and R packages, such as numpy, scipy, ggplot2 etc. But there are situations a user may just want to compute a simple thing from R. Additionally, I found that the interface of
rpy2 is not very discoverable.
rchitectis a brother of
I am the same developer behind the Julia package
RCall.jl which allows Julia to communicate with R.
RCall.jl share a very similar design. For example,
rcopy(reval("1")) works for both
rchitectis compatible with
reticulate. Objects can be converted seamlessly between
reticulate. Check the section for
rchitect may fail to open the shared library.
- On Linux
First, try to expose R to PATH.
Note that it should be the path to
R_HOME, not the path to the R binary. The
folder should contain a file called
COPYING. In some cases, you may need to
$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`R RHOME`/lib"
- On Windows
Make sure that the path(s) to
R.dll is in the
Very minimal API
from rchitect import *
reval- evaluate an R expression in the global environment
a = reval("1:5")
rcopy- convert any RObject returned by
revalto its python type
b = rcopy(a)
robject- convert any python object to its R type
c = robject(b)
rcall- call an R function. Python objects are converted to RObjects implicitly.
d = rcall("sum", c)
# some preparation work # Unix users may need this PR: https://github.com/rstudio/reticulate/pull/279 # Windows + Python 2.7 users may need this PR: https://github.com/rstudio/reticulate/pull/335 # See also https://github.com/randy3k/radian#how-to-specify-r_home-location from rchitect import * reval("library(reticulate)"); py_object = reval("r_to_py(LETTERS)") rcopy(py_object) class Foo(object): pass foo = Foo() rcall("r_to_py", robject(foo))
library(reticulate) py_run_string("from rchitect import *") r_object = py_eval("reval('LETTERS')") py_to_r(r_object) py_run_string("class Foo(object): pass") py_run_string("foo = Foo()") py_object = py_eval("robject(foo)") r_to_py(py_to_r(py_object))
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size rchitect-0.2.4.tar.gz (23.6 kB)||File type Source||Python version None||Upload date||Hashes View hashes|