I've been playing around with RPy a bit this morning. As the main page says:
rpy2 is a redesign and rewrite of rpy. It is providing a low-level interface to R, a proposed high-level interface, including wrappers to graphical libraries, as well as R-like structures and functions.
I just used
easy_install
For some reason,
root
was the owner of the .pth file. So I changed it, and then got:The example I chose to run was described in more detail in this post. If we run it from R, it looks like this:
In R, the variable
result
is a list of numeric vectors with names:$posterior, $likelihood, $prior, $pi
(990 elements each), $mean, $var, $sd, $quantiles
.In the Python interpreter:
and it opens X11 (rather than Quartz, not sure why) to do the plot. Getting the individual values from the result is a slight pain, but not too bad:
To get the names of the vectors, we need to parse
str(result)
after splitting on double newlines. If you already know the index of the value you want you can just grab it directly as shown. And of course, that's better, since the value is a float rather than a string.[UPDATE: As the first comment says, using
names
is the way to do this. Docs here. And see examples in later posts.]