rpy2

Prepare a python string for R using rpy2

余生颓废 提交于 2019-11-29 12:59:05
This question relates to python variable to R and perhaps also to this python objects to rpy2 but none of the two completely overlaps and the first one is actually unanswered. My question is actually very simple. I have a string, say: In [21]: strg Out[21]: 'I want to go home' and I want to pass it to R through robjects.r(''' ''') like this, for example: robjects.r(''' test <- gsub("to", "",strg) ''') but of course, when I run this I obtain: Error in gsub("me", "", strg) : object 'strg' not found . I have not used rpy2 much (as obvious) but I guess is related to the environments in which R and

Tried to guess R's HOME but no R command in the PATH. OsX 10.6

余生颓废 提交于 2019-11-29 06:19:03
I am trying to install rpy2 and I am facing a common issue. Unfortunately all the solution I have found are for win7 I have installed a Python 2.7 and R 2.15. then I write on the terminal easy_install rpy2 or, alternatively pip install rpy2 Same result: Tried to guess R's HOME but no R command in the PATH What I should do? Make sure you have R installed brew install r Then install rpy pip install rpy2 Aaron McDaid The rpy2 code is doing the wrong check. R might be perfectly fine, but rpy2 is using an unreliable check. To check for R , the rpy2 uses subprocess.check_output . However, that was

Rpy2 error wac-a-mole: R_USER not defined

喜你入骨 提交于 2019-11-29 00:15:35
I'm running Python (x,y) 2.7 on windows 7 32 bit and R version 3.1.0. I've been trying to install Rpy2 and have been getting many errors. I finally found this site which has pre-compiled python modules for windows http://www.lfd.uci.edu/~gohlke/pythonlibs/ , so I downloaded rpy2‑2.4.2.win32‑py2.7.exe. When I did this and tried import rpy2.robjects as robjects I had an error saying it could not find R_HOME, so I updated my path variables. This was fixed, but then I got an error saying it could not find R_USER. Once again, I updated my PYTHONPATH variables based on SO responses. This didn't work

Calling Custom functions from Python using rpy2

纵然是瞬间 提交于 2019-11-28 23:38:01
Is there a way to call functions defined in a file say myfunc.r ---------------myfunc.r -------------- myfunc = function(){ return(c(1,2,3,4,5,6,7,8,9,10)) } getname = function(){ return("chart title") } ---- Python How to call getname() here ? Any help would be greatly appreciated ? The are features in rpy2 that should help making this cleaner than dumping objects into the global workspace. from rpy2.robjects.packages import STAP # if rpy2 < 2.6.1 do: # from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage # STAP = SignatureTranslatedAnonymousPackage with open('myfunc.r', 'r'

How to implement R's p.adjust in Python

可紊 提交于 2019-11-28 17:06:00
I have a list of p-values and I would like to calculate the adjust p-values for multiple comparisons for the FDR . In R, I can use: pval <- read.csv("my_file.txt",header=F,sep="\t") pval <- pval[,1] FDR <- p.adjust(pval, method= "BH") print(length(pval[FDR<0.1])) write.table(cbind(pval, FDR),"pval_FDR.txt",row.names=F,sep="\t",quote=F ) How can I implement this code in Python? Here was my feable attempt in Python with the help of Google: pvalue_list [2.26717873145e-10, 1.36209234286e-11 , 0.684342083821...] # my pvalues pvalue_lst = [v.r['p.value'] for v in pvalue_list] p_adjust = R.r['p

Error when installing rpy2 module in Python with easy_install

天大地大妈咪最大 提交于 2019-11-28 13:03:10
I've been trying to install the rpy2 module so I can use R functions inside my Python script, but I'm getting an error after following the advice from these pages: 1) Tried to guess R's HOME but no R command in the PATH. OsX 10.6 2) http://rpy.sourceforge.net/rpy2/doc-dev/html/overview.html What I've done so far: 1) Edited my path environment variable to include "C:\Program Files\R\R-3.1.0\bin\x64;" 2) Created a new environment variable called "R_HOME" and set its value to "C:\Program Files\R\R-3.1.0" 3) Created a new environment variable called "R_USER" and set its value to "Hefin" (my

Calling R Script from python in AWS lambda

只谈情不闲聊 提交于 2019-11-28 13:01:15
I know there is a package called rpy2 in python in order to integrate R and python. Calling R script from python using rpy2 , in this link they have described to do normally. But in order do the same in AWS lambda, what should be the path that we can give instead of the name "folder" in this link. I am using very simple methode for interachanging between python and R by using rpy2, here is one example where I write R script as string and then use rpy2 to translate it for R and return it back, path="H:/projects/somepackage/CODE" from rpy2.robjects.packages import

Getting Segmentation fault Core dumped error while importing robjects from rpy2

社会主义新天地 提交于 2019-11-28 11:40:15
Installed R and rpy2 manually Installation is successful but getting the above mentioned error. Please help me out? Outputs of some useful commands: >>> import rpy2 >>> rpy2.__path__ ['/home/ashish/miniconda2/lib/python2.7/site-packages/rpy2-2.8.2-py2.7-linux-x86_64.egg/rpy2'] >>> import rpy2.robjects cannot find system Renviron /home/ashish/miniconda2/lib/python2.7/site-packages/rpy2-2.8.2-py2.7-linux- x86_64.egg/rpy2/rinterface/__init__.py:185: RRuntimeWarning: Fatal error: unable to open the base package warnings.warn(x, RRuntimeWarning) Segmentation fault (core dumped) Thanks in advance..

Clearing memory used by rpy2

大兔子大兔子 提交于 2019-11-28 10:20:55
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 R’s garbage collection until foo is deleted from Python but even doing: import rpy2.robjects as r a =

Unable to install R package in python (Jupyter notebook)?

假如想象 提交于 2019-11-28 06:50:07
问题 I am trying to install R package on python 3x in the jupyter notebook. I understand that I have to pip install rpy2 and it has been successful This works fine when I call a built-in function in R such as ccf or other easy issues. # Call function from R import os os.environ['R_USER'] = 'D:\Anaconda3\Lib\site-packages\rpy2' import rpy2.robjects as robjects from rpy2.robjects import pandas2ri pandas2ri.activate() However, if I want to install a package such as DirichletReg or vars , it is not