rpy2

rpy2 installation on Ubuntu

爱⌒轻易说出口 提交于 2019-12-05 17:08:52
I'm pretty new to Linux and I'm having some serious trouble installing Rpy2. I had an older versions of Rpy2 installed by the synaptic package manager, but I needed an updated version and removed it (all files in the Rpy2 directory as described in the Rpy2 documentation). I downloaded the tar.gz. from SourceForge and ran this code: tar -xzf rpy2-2.1.8.tar.gz cd rpy2-2.1.8 python setup.py build install It appeared to be copying files as it should, but then multiple pages of error messages (highlighted in bold ) just start floating: running build_ext Configuration for R as a library: include

Rpy2 import external R file

别等时光非礼了梦想. 提交于 2019-12-05 14:41:37
I have a R script in a .R file that I would like to execute. How can I load it? I'd like to source("/path/to/file.R") within the python code, but with this name! Simply import R's source function like any other! import rpy2.robjects as robjects r_source = robjects.r['source'] r_source("path/to/file.R") I use a trick to have both R code and Python script in my editor, you can have a look at this example https://stackoverflow.com/a/55900840/5350311 , I hope it is useful for you. 来源: https://stackoverflow.com/questions/19567081/rpy2-import-external-r-file

creating multiple scatter plots with same axes in R

不问归期 提交于 2019-12-05 12:21:51
I'm trying to plot four scatter plots in 2 x 2 arrangement in R (I'm actually plotting via rpy2). I'd like each to have an aspect ratio of 1 but also be on the same scale, so identical X and Y ticks for all the subplots so that they can be compared. I tried to do this with par : par(mfrow=c(2,2)) # scatter 1 plot(x, y, "p", asp=1) # scatter 2 plot(a, b, "p", asp=1) # ... Edit: Here's a direct example of what I have now: > par(mfrow=c(2,2)) > for (n in 1:4) { plot(iris$Petal.Width, rnorm(length(iris$Petal.Width)), "p", asp=1) } which creates the right type of scatter but with different scales.

translating named list vectors from R into rpy2 in Python?

你。 提交于 2019-12-05 08:04:23
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 Class1 Class2 "navy" "darkgreen" Is it an robject.ListVector ? I tried: robjects.ListVector({"Class1": "navy", "Class2": "green"}) but it's not quite it because I'm not sure how to tell the ListVector object that the name of this object is Var1 , i.e. something like list(Var1 = Var1) . How can this be properly translated to rpy2? If I understand right

Python rpy2 and quantmod examples

孤者浪人 提交于 2019-12-05 05:01:59
问题 Python programming language has helped me a lot in developing financial data analysis applications. Alternatively, there is the R for data analysis too, which has dedicated financial data analysis packages, for example: quantmod. Now, that there is rpy2 to interface between both these languages(i.e. Python & R). I would like to prototype some financial data analysis applications using the power of python with the quantmod package. By now, I have spent several hours searching the internet for

convert numpy array to Matrix rpy2, Kmeans

余生颓废 提交于 2019-12-05 03:57:21
问题 I have a numpy 2D array self.sub and i want to use it in rpy2 kmeans. k = robjects.r.kmeans(self.sub,2,20) i always get the following error: valueError: nothing can be done for the type at the moment! what can i do? 回答1: From the rpy2 docs, R matrices are just vectors with their dim attribute set. So for a numpy two-dimensional array x import rpy2.robjects as robj nr, nc = x.shape xvec = robj.FloatVector(x.transpose().reshape((x.size)) xr = robj.r.matrix(xvec, nrow=nr, ncol=nc) You have to

How to preserve Labels when SPSS file (.sav) imported into pandas via rpy?

眉间皱痕 提交于 2019-12-05 03:24:05
I'm looking to work on a SPSS files (.sav) using pandas . In the absence of the SPSS program, here's what a typical file looks like when converted to .csv: On investigation into what the first two rows signify (I don't know SPSS), it seems that the first row contains the Label s, while the second row contains the VarName s. When I bring the file into pandas thus: import pandas.rpy.common as com def savtocsv(filename): w = com.robj.r('foreign::read.spss("%s", to.data.frame=TRUE)' % filename) w = com.convert_robj(w) return w and then do a head(), the first row (Label) is missing: How can labels

Installing the R interpeter and R as a shared library uder the same tree

a 夏天 提交于 2019-12-05 02:21:01
I am a bit confused about how to install R (via compilation) as a shared library. The instructions here ( Rpy2 ) say that I should do the following: # <go to the R source directory> make distclean ./configure --enable-R-shlib make make install but the first make ( make distclean ) would remove any previous installation of R under the same directory tree (e.g. the contents of the bin folder). What if I want to use the same installation for the R interpreter and the shared libraries? For example, say I want to use the interpreter to install R packages, and then the shared library of the

Ipython notebook crash using rmagic extension

别等时光非礼了梦想. 提交于 2019-12-04 15:12:53
I am trying to run the rmagic functions extension example, but ipython crashes with console error message '\u used without hex digits in character string starting "c:\u". I suspect that this is an R error message caused by rmagic passing c:\path instead of c:\ or c:/. There is probably an easy way to fix this (IPython or Notebook startup parameters?) , but, as a newbie to rmagic and rpy2, I need some expert help please. The following simple snippet from the example causes the kernel to die: import rpy2 %load_ext rmagic %R x=1 I am a windows user... Found a solution to this ipython/windows

RPY2: importr fails with .Renviron

烂漫一生 提交于 2019-12-04 13:48:25
问题 Here's what should and does happen using rpy2.robjects.packages.importr for base R-packages (e.g. stats ): >>> from rpy2.robjects.packages import importr >>> importr('stats') <rpy2.robjects.packages.SignatureTranslatedPackage object at 0x7f3810> but with an external package (e.g. ggplot2 ) this is the result: >>> importr('ggplot2') Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'ggplot2' Error in .Primitive(