rpy2

Passing vectors and params from Python to R functions

故事扮演 提交于 2019-12-08 03:38:18
问题 I am learning Python and R and am having an issue passing parameters from Python to an R function named "Contours". The below works..... Python (testr.py) import rpy2.robjects as robjects robjects.r(''' source('Wrapper.R') ''') r_myfunc = robjects.globalenv['Contours'] r_myfunc() R (Wrapper.R) source ('./DrawCompRecVark.R') imageDirectory="./tmp/" Contours <- function() { k=c(0,1) sens=c(0.8, 0.9, 0.95, 0.995) spec=0.8 prev=0.001 N=1 uniqueId=1 #graph prepareSaveGraph(imageDirectory,

rpy2 windows Unable to unlink tempfile

拈花ヽ惹草 提交于 2019-12-08 02:45:36
问题 I'm using Python 3.3, R-3.0.1, Win7-64. I'm getting an "Unable to unlike tempfile" in rpy2.robject (ln 48). Looking at it, some other process (presumably R) has hold of the file when Python is trying to release it. It's not a major problem, but it's not clear how I might fix it. Anyone else seen this? Ideas? --Don 来源: https://stackoverflow.com/questions/16992115/rpy2-windows-unable-to-unlink-tempfile

Pass list from python to R through rpy2

北城以北 提交于 2019-12-08 02:43:25
问题 I'm trying to make a simple call to a R package ( ks ) from within python through rpy2. This is what I would like to achieve: import rpy2.robjects as robjects # Define two matrices. matrix1 = [[1,1,1,1], [3,3,3,3]] matrix2 = [[1,1,1,1], [3,3,3,3]] # Call 'ks' function to obtain p_value. p_val = robjects.r(''' library(ks) kde.test(x1=matrix1, x2=matrix2)$pvalue''') print p_val I tried following the documentation from rpy2 but it is very scarce. Any help would be appreciated. 回答1: Posting my

rpy2: check if package is installed

落爺英雄遲暮 提交于 2019-12-08 02:04:53
问题 Using rpy2 , I want to check if a given package is installed. If it is, I import it. If not, I install it first. How do I check if it's installed? from rpy2 import * if not *my package is installed*: rpy2.interactive as r r.importr("utils") package_name = "my_package" r.packages.utils.install_packages(package_name) myPackage = importr("my_package") 回答1: Here is a function that'd do it on the Python side (note the contriburl , that should be set to a CRAN mirror, and that the case where

rpy2 installation error (OS: linux mint 17 | R 3.1.2 | python 2.7.6)

无人久伴 提交于 2019-12-07 18:33:56
问题 When I run 'sudo pip install rpy2' I get the a lot of compilation errors. Here is the full dump of all the errors and here is an example except: Compilation parameters for rpy2's C components: include_dirs = ['/usr/share/R/include'] library_dirs = ['/usr/lib/R/lib'] libraries = ['R', 'pcre', 'lzma', 'bz2', 'z', 'rt', 'dl', 'm'] extra_link_args = ['-Wl,--export-dynamic', '-fopenmp'] R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" building 'rpy2.rinterface._rinterface' extension x86_64-linux

problems sourcing in an .R file into python using rpy2

廉价感情. 提交于 2019-12-07 12:06:50
问题 In rpy 1.x, to source in a .R file, all one had to do was this: import rpy rpy.r.source("filename.R") In rpy2, what needs to happen in order to source in a .R file from Python? I have tried several avenues, such as this: import rpy2.robjects as ro ro.source("filename.R") Returns an error like this (sorry if this doesn't format correctly): File "C:\Python27\lib\site-packages\rpy2\robjects\functions.py", line 166, in __call__ return super(SignatureTranslatedFunction, self).__call__(*args, *

rpy2 installation on Ubuntu

家住魔仙堡 提交于 2019-12-07 11:41:40
问题 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

Installing rpy2 for Python 3 using pip

只愿长相守 提交于 2019-12-07 11:30:23
问题 I am trying to install the rpy2 package for python 3 on Windows 7. So I simply typed pip install rpy2 in the command line. However, it fails for a reason I do not understand, could anyone clear this up please? It threw back the following in the command line: Collecting rpy2 Using cached rpy2-2.8.2.tar.gz Complete output from command python setup.py egg_info: Warning: Tried to guess R's HOME but no command <R> in the PATH. _______________________________ Command "python setup.py egg_info"

Rpy2 import external R file

三世轮回 提交于 2019-12-07 10:54:06
问题 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! 回答1: 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") 回答2: 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. 来源:

Installing python module “rpy2” after installing Enthought Canopy

a 夏天 提交于 2019-12-07 09:44:18
问题 Some of my python scripts use rpy2 as an interface to R, which worked perfectly with the previous Enthought EPD python. I recently installed Canopy Python from Enthought. Python now no longer finds the rpy2 module, and when I try to reinstall it, I get the following errors: $ easy_install rpy2 [...] Processing rpy2-2.3.5.tar.gz Writing /var/folders/9n/qk8wf11d205b0lrr57wyg7k80000gp/T/easy_install-HIclIh/rpy2-2.3.5/setup.cfg Running rpy2-2.3.5/setup.py -q bdist_egg --dist-dir /var/folders/9n