Questions tagged [rpy2]

RPy is a very simple, yet robust, Python interface to the R Programming Language. It can manage all kinds of R objects and can execute arbitrary R functions (including the graphic functions). All errors from the R language are converted to Python exceptions. Any module installed for the R system can be used from within Python

RPy is a very simple, yet robust, Python interface to the R Programming Language. It can manage all kinds of R objects and can execute arbitrary R functions (including the graphic functions). All errors from the R language are converted to Python exceptions. Any module installed for the R system can be used from within Python.

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.

https://rpy2.bitbucket.io

1203 questions
7
votes
3 answers

How to plot (inline) with rpy2 in Jupyter notebook?

I'm learning to use rpy2 in Jupyter notebook. I'm having troubles with the plotting. When I use this example from the rpy2 docs for interactive work: from rpy2.interactive import process_revents from rpy2.robjects.packages import importr from…
Artturi Björk
  • 3,643
  • 6
  • 27
  • 35
7
votes
1 answer

Using R in Apache Spark

There are some options to access R libraries in Spark: directly using sparkr using language bindings like rpy2 or rscala using standalone service like opencpu It looks like SparkR is quite limited, OpenCPU requires keeping additional service and…
user6022341
7
votes
2 answers

Is there a way to access R data frame column names in python/rpy2?

I have an R data frame, saved in Database02.Rda. Loading it import rpy2.robjects as robjects robjects.r.load("Database02.Rda") works fine. However: print(robjects.r.names("df")) yields NULL Also, as an example, column 214 (213 if we count…
0range
  • 2,088
  • 1
  • 24
  • 32
7
votes
2 answers

Error install rpy2: 'sh' is not recognized as an internal or external command, operable program or batch file

I try install rpy2 but I have this error below. I read in the web that the problem it's the Environment Variables but I have C:\Rtools\bin and C:\Program Files\R\R-3.2.2\bin in System Variable Path. what am I doing…
Kardu
  • 865
  • 3
  • 13
  • 24
7
votes
3 answers

how to select columns from R dataframe in rpy2 in python?

I have a dataframe in rpy2 in python and I want to pull out columns from it. What is the rpy2 equivalent of this R code? df[,c("colA", "colC")] this works to get the first column: mydf.rx(1) but how can I pull a set of columns, e.g. the 1st, 3rd and…
lgd
  • 1,472
  • 5
  • 17
  • 35
7
votes
1 answer

Installing pywin32 - win32api.pyd permission denied

I need to use win32api for rpy2. So I went to http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32 and tried to install it with pip. However, I have got the errors below. How can I overcome this permission denied problem?…
twfx
  • 1,664
  • 9
  • 29
  • 56
7
votes
1 answer

How to convert numpy array to R matrix?

How do you convert a numpy array to a R matrix using rpy2? This might be trivial, but I cannot find a good answer in the documentation. I can get this working by first converting to a pandas dataframe as an extra step, but this seems…
fileunderwater
  • 1,125
  • 2
  • 12
  • 31
7
votes
2 answers

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…
Mike Dewar
  • 10,945
  • 14
  • 49
  • 65
7
votes
1 answer

IPython notebook and rmagic/rpy2: cannot find module ri2py (OSX 10.8.5, python 2.7, R 3.1)

I'm trying to use the rmagic extension for the IPython notebook, using Python 2.7.6 via Enthought Canopy. When I try the following example: import numpy as np import pylab X = np.array([0,1,2,3,4]) Y = np.array([3,5,4,6,7]) pylab.scatter(X,…
user3683206
  • 73
  • 1
  • 3
7
votes
2 answers

Load high-dimensional R dataset into Pandas DataFrame

Some R datasets can be loaded into a Pandas DataFrame or Panel quite easily: import pandas.rpy.common as com infert = com.load_data('infert') print(infert.head()) This appears to work as long as the dimension of the R dataset is <= 3. Higher…
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
7
votes
2 answers

translating named list vectors from R into rpy2 in Python?

What is the equivalent of the following R code in Rpy2 in python? Var1 = c("navy", "darkgreen") names(Var1) = c("Class1", "Class2") ann_colors = list(Var1 = Var1) It's not clear what ann_colors is. When evaluated in R it gives: > ann_colors $Var1 …
user248237
7
votes
3 answers

issue converting python pandas DataFrame to R dataframe for use with rpy2

I am having trouble converting a pandas DataFrame in Python to an R object, for future use in R using rpy2. The new pandas release 0.8.0 (released a few weeks ago) has a function to convert pandas DataFrames to R DataFrames. The problem is in…
yayder9990
  • 83
  • 1
  • 4
6
votes
1 answer

difficulty installing rpy2 using Python 3.8 via anaconda with R version 4.0.2 on Mac osx

I have never used R code in python before, but would like to do so in order to implement some Poisson regression models. The reason for this is efficiency (R code for poisson regression much more efficient). I have attempted to install rpy2 by…
6
votes
3 answers

How to correctly set up rpy2?

I'm trying to run rpy2 with no success. After installing R and rpy2, I tried testing rpy2 as instructed in the rp2 documentation: from IDLE: import rpy2.situation for row in rpy2.situation.iter_info(): print(row) I'm getting the following…
random
  • 146
  • 2
  • 10
6
votes
3 answers

How to load R's .rdata files into Python?

I am trying to convert one part of R code in to Python. In this process I am facing some problems. I have a R code as shown below. Here I am saving my R output in .rdata format. nms <- names(mtcars) save(nms,file="mtcars_nms.rdata") Now I have to…
RSK
  • 751
  • 2
  • 7
  • 18