rpy2

How do Rpy2, pyrserve and PypeR compare?

妖精的绣舞 提交于 2019-11-27 06:24:43
I would like to access R from within a Python program. I am aware of Rpy2, pyrserve and PypeR. What are the advantages or disadvantages of these three options? I know one of the 3 better than the others, but in the order given in the question: rpy2: C-level interface between Python and R (R running as an embedded process) R objects exposed to Python without the need to copy the data over Conversely, Python's numpy arrays can be exposed to R without making a copy Low-level interface (close to the R C-API) and high-level interface (for convenience) In-place modification for vectors and arrays

Clearing memory used by rpy2

痴心易碎 提交于 2019-11-27 03:32:16
问题 How can I clear objects (and the memory they occupy) created via rpy? import rpy2.robjects as r a = r.r('a = matrix(NA, 2000000, 50)') del a #if I do this, there is no change in the amount of memory used r.r('rm(list=(ls(all=TRUE)))') # Same here, the objects disappear, but the memory is still used The unfortunate effect is that in my application, memory usage increases until there is not enough and then it crashes... From the rpy2 docs: The object itself remains available, and protected from

Converting python objects for rpy2

試著忘記壹切 提交于 2019-11-27 03:31:41
The following code is supposed to create 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\site-packages\rpy2\robjects\__init__.py", line 418, in __call__ new_args = [conversion.py2ri(a) for a in args] File "C:\Python25\lib\site-packages\rpy2\robjects\__init__.py", line 93, in default_py2ri raise(ValueError("Nothing can be done for the type %s at the moment." %(type

Minimal example of rpy2 regression using pandas data frame

試著忘記壹切 提交于 2019-11-27 01:36:31
问题 What is the recommended way (if any) for doing linear regression using a pandas dataframe? I can do it, but my method seems very elaborate. Am I making things unnecessarily complicated? The R code, for comparison: x <- c(1,2,3,4,5) y <- c(2,1,3,5,4) M <- lm(y~x) summary(M)$coefficients Estimate Std. Error t value Pr(>|t|) (Intercept) 0.6 1.1489125 0.522233 0.6376181 x 0.8 0.3464102 2.309401 0.1040880 Now, my python (2.7.10), rpy2 (2.6.0), and pandas (0.16.1) version: import pandas import

rpy2 install on windows 7

只谈情不闲聊 提交于 2019-11-27 00:28:18
I'm trying to install rpy2 on my computer, but I wasn't able to do it. I downloaded the source package and I tryed to install Rpy2 (rpy2-2.3.2) using the command python setup.py install . This is the result: running install running build running build_py running build_ext "C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config --ldflags "C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config --cppflags "C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config LAPACK_LIBS returned an empty string. "C:\PROGRA~1\R\R-215~1.2\bin\R" CMD config BLAS_LIBS returned an empty string. Configuration for R as a library: include_dirs: ('C:/PROGRA

Python interface for R Programming Language [duplicate]

帅比萌擦擦* 提交于 2019-11-26 23:50:49
问题 This question already has an answer here: How do Rpy2, pyrserve and PypeR compare? 4 answers I am quite new to R, and pretty much used to python. I am not so comfortable writing R code. I am looking for python interface to R, which lets me use R packages in pythonic way . I have done google research and found few packages which can do that: Rpy2 PypeR pyRserve But not sure which one is better ? Which has more contributers and more actively used ? Please note my main requirement is pythonic

controlling order of points in ggplot2 in R?

让人想犯罪 __ 提交于 2019-11-26 21:58:54
Suppose I'm plotting a dense scatter plot in ggplot2 in R where each point might be labeled by a different color: df <- data.frame(x=rnorm(500)) df$y = rnorm(500)*0.1 + df$x df$label <- c("a") df$label[50] <- "point" df$size <- 2 ggplot(df) + geom_point(aes(x=x, y=y, color=label, size=size)) When I do this, the scatter point labeled "point" (green) is plotted on top of the red points which have the label "a". What controls this z ordering in ggplot, i.e. what controls which point is on top of which? For example, what if I wanted all the "a" points to be on top of all the points labeled "point"

Calling R script from python using rpy2

蓝咒 提交于 2019-11-26 19:19:43
问题 I'm very new to rpy2, as well as R. I basically have a R script, script.R, which contains functions, such as rfunc(folder). It is located in the same directory as my python script. I want to call it from Python, and then launch one of its functions. I do not need any output from this R function. I know it must be very basic, but I cannot find examples of R script-calling python codes. What I am currently doing, in Python: import rpy2.robjects as robjects def pyFunction(folder): #do python

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

守給你的承諾、 提交于 2019-11-26 16:07:26
问题 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 function of X and Y i.e. Y ~ f(X,Y). I assume that I will somehow need to transform my Y variables, but I have not seen any example yet, that shows how to do this. So,

How do Rpy2, pyrserve and PypeR compare?

混江龙づ霸主 提交于 2019-11-26 11:59:43
问题 I would like to access R from within a Python program. I am aware of Rpy2, pyrserve and PypeR. What are the advantages or disadvantages of these three options? 回答1: I know one of the 3 better than the others, but in the order given in the question: rpy2: C-level interface between Python and R (R running as an embedded process) R objects exposed to Python without the need to copy the data over Conversely, Python's numpy arrays can be exposed to R without making a copy Low-level interface