rpy2

Python and Rpy2: Calling plot function with options that have "." in them

I'm just starting to learn how to use rpy2 with python. I'm able to make simple plots and such, but I've run into the problem that many options in R use ".". For example, here's an R call that works: barplot(t, col=heat.colors(2), names.arg=c("pwn", "pwn2")) where t is a matrix. I want to use the same call in python, but it reje...

Converting python objects for rpy2

The following code is supposed to created a heatmap in rpy2 import numpy as np from rpy2.robjects import r data = np.random.random((10,10)) r.heatmap(data) However, it results in the following error Traceback (most recent call last): File "z.py", line 8, in <module> labRow=rowNames, labCol=colNames) File "C:\Python25\lib\...

rpy2: Converting a data.frame to a numpy array

I have a data.frame in R. It contains a lot of data : gene expression levels from many (125) arrays. I'd like the data in Python, due mostly to my incompetence in R and the fact that this was supposed to be a 30 minute job. I would like the following code to work. To understand this code, know that the variable path contains the full pa...

How to suppress error messages in rpy2

Hello! The following code does not work. It seems that the R warning message raises a python error. # enable use of python objects in rpy2 import rpy2.robjects.numpy2ri import numpy as np from rpy2.robjects import r # create an example array a = np.array([[5,2,5],[3,7,8]]) # this line leads to a warning message, which in turn raises ...

Plotting 3-tuple data points in a surface / contour plot using matplotlib

I have some surface data that is generated by an external program as XYZ values. I want to create the following graphs, using matplotlib: Surface plot Contour plot Contour plot overlayed with a surface plot I have looked at several examples for plotting surfaces and contours in matplotlib - however, the Z values seems to be a functio...

Python and rpy2: How do I adjust/clear a graphic during runtime?

I'm using rpy2 to do data analysis and plotting in python. It works fine except for the fact that when I draw a plot, it's window hangs around until the program terminates. Is there a way to clear the plot during runtime? Additionally, If I ever resize the window, the plot disappears, but the window remains. When using R interactively, r...

Python Rpy R data processing optimization

I am writing a data processing program in Python and R, bridged with Rpy2. Input data being binary, I use Python to read data out and pass them to R, then collect results to output. Data are organized into pieces, each being around 100 Bytes (1Byte per value * 100 values). They just work now, but the speed is very low. Here are some o...

issue running a test in Python, via rpy2

I have a feeling this will be a quick fix, given that I started coding two weeks ago. I am try to run a statistical test - a Mantel, looking for a correlation between two distance matrices - in Python, by using a function(?) that has already been written in R, via Rpy2. The R module is "ade4" and it contains "mantel.rtest" from rpy2 im...

Mapping python tuple and R list with rpy2 ?

Hello guys, I'm having some trouble to understand the mapping with rpy2 object and python object. I have a function(x) which return a tuple object in python, and i want to map this tuple object with R object list or vector. First, i'm trying to do this : # return a python tuple into this r object tlist robjects.r.tlist = get_max_ticks...

issue running a program (R) in Python to perform an operation (execute a script)

Hi all, I'm tying to execute an R script from python, ideally displaying and saving the results. Using rpy2 has been a bit of a struggle, so I thought I'd just call R directly. I have a feeling that I'll need to use something like "os.system" or "subprocess.call," but I am having difficulty deciphering the module guides. Here's the R...

How to create an empty R vector to add new items

Hi, I want to use R in Python, as provided by the module Rpy2. I notice that R has very convenient [] operations by which you can extract the specific columns or lines, how could I achieve such a function by python scripts? My idea is to create a R vector and add those wanted elements into this vecotr so that the final vector is the same...

Convert a R code into Python script

Hi, I got the following R code and I need to convert it to python and run it in python environment, basically I have done this with rpy2 module, but it looks kind of dull with python doing the same things, so could someone find a better way to rewrite the following R code to an equivalent python script with the rpy2 module? mymad <- fun...

ggplot2 hell with rpy2-2.0.7 + python 2.6 + r 2.11 (windows 7)

i am using rpy2-2.0.7 (i need this to work with windows 7, and compiling the binaries for the newer rpy2 versions is a mess) to push a two-column dataframe into r, create a few layers in ggplot2, and output the image into a <.png>. i have wasted countless hours fidgeting around with the syntax; i did manage to output the files i neede...

passing R function arguments in rpy

I have the following two lines of code that both run fine in both R and Python (via Rpy): [R] rcut = cut(vector, brks) [Python] rcut = r.cut(vector, brks) However, if I want to add the argument of include.lowest=TRUE, it runs as expected in R: [R] rcut = cut(vector, brks, include.lowest=TRUE) But it doesn't work in Rpy: [Python] r...

Sorted quantile mean via Rpy

The real goal here is to find the quantile means (or sums, or median, etc.) in Python. Since I'm not a power user of Python but have used R for a while, my chosen route is via Rpy. However, I ran into the problem that the returned list of means are not correspondent to the order of the quantiles. In particular, I have the followings in R...

How to Install rpy2 on Mac OS X

Hi everyone, I am trying, so far unsuccessfully, at installing the rpy2 for python on my Mac OSX. I have tried Macports and DarwinPorts but have had no luck with import rpy2 within the python shell environment. I don't know much about programming in Mac and I am a wiz at installing modules on a Windoze based system, but for the life of...

Mapping result of psycopg2 into dataframe for R with RPY2

Hello Guys, With psycopg2, i get result of query in this form : [(15002325, 24, 20, 1393, -67333094L, 38, 4, 493.48763257822799, 493.63348372593703), (15002339, 76, 20, 1393, -67333094L, 91, 3, 499.95845909922201, 499.970048093743), (15002431, 24, 20, 1394, -67333094L, 38, 4, 493.493464900383, 493.63348372593703), (150024...

Installing rpy2 -2.1.5 on Mac OS X 10.5.8 fails

Hello, I've searched far and wide, read a previous question in stackoverflow but cant seem to solve the problem of installing rpy2 on my Mac with OS X 10.5.8. I have Xcode 3.1.4 installed and R 2.1.11. when I run: sudo python setup.py build install I get this: running build running build_py running build_ext building 'rpy2.rinterfac...