rpy2

Create temporary dataframe with rpy2: memory issue

烂漫一生 提交于 2019-12-24 11:29:28
问题 This question is similar to but simpler than my previous one. Here is the code that I use to create R dataframes from python using rpy2: import numpy as np from rpy2 import robjects Z = np.zeros((10000, 500)) df = robjects.r["data.frame"]([robjects.FloatVector(column) for column in Z.T]) My problem is that using it repetitively results in huge memory consumption. I tried to adapt the idea from here but without success. How can I convert many numpy arrays to dataframe for treatment by R

pandas and rpy2: Why does ezANOVA work via robjects.r but not robjects.packages.importr?

时光怂恿深爱的人放手 提交于 2019-12-24 08:36:34
问题 Like many, I'm hoping to stop straddling R and Python worlds and just work in Python using Pandas, Pyr2, Numpy, etc. I'm using the R package ez for its ezANOVA facility. It works if I do things the hard way, but why doesn't it work when I do them the easy way? I don't understand the resulting error: File "/Users/malcomreynolds/analysis/r_with_pandas.py", line 38, in <module> res = ez.ezANOVA(data=testData, dv='score', wid='subjectid', between='block', detailed=True) File "/usr/local/lib

Can rpy2 code be run in parallel?

橙三吉。 提交于 2019-12-24 08:36:12
问题 I have some Python code that passes a data frame to R via rpy2, whereupon R processes it and I pull the resulting data.frame back to R as a PANDAS data frame via com.load_data . The thing is, the call to com.load_data works fine in a single Python process but it crashes when the same bunch of code is run in several multiprocessing.Process processes concurrently. I get the following error message out of Python: File "C:\\Python27\\lib\\site-packages\\pandas\\rpy\\common.py", line 29, in load

Count most frequent word in row by R

别说谁变了你拦得住时间么 提交于 2019-12-24 08:04:38
问题 There is a table shown below Name Mon Tue Wed Thu Fri Sat Sun 1 John Apple Orange Apple Banana Apple Apple Orange 2 Ricky Banana Apple Banana Banana Banana Banana Apple 3 Alex Apple Orange Orange Apple Apple Orange Orange 4 Robbin Apple Apple Apple Apple Apple Banana Banana 5 Sunny Banana Banana Apple Apple Apple Banana Banana So , I want to count the most frequent Fruit for each person and add those value in new column. For example. Name Mon Tue Wed Thu Fri Sat Sun Max_Acc Count 1 John Apple

Python 2.7 - Rpy2 Cox Proprotional Hazards Model

我是研究僧i 提交于 2019-12-24 00:15:50
问题 I am using Python 2.7 on Mac OSX Lion and will be installing rpy2 to use Cox Proportional Hazards Model I was just wondering: has anybody used rpy2 to do Cox Proportional Hazards before. I was reading some of the documentation on the rpy2 package and it mostly talks about creating dataframes and such, as opposed to stating how various functions can be run. So, how would I go about calling this function and then specifying the dependent time variable , as well as the censoring variable

Accessing a R user defined function in Python

别来无恙 提交于 2019-12-23 18:46:28
问题 So I need to do Principle Component Regression with cross validation and I could not find a package in Python that would do so. I wrote my own PCR class but when tested against R's pls package it performs significantly worse and is much slower on high dimensional data (~50000 features) which I am still not sure why but that is another question. Because all of my other code is in python, and in the interest of saving time I decided the best way might just be able to write an R function that

How to install rpy2 via conda using default R installation

℡╲_俬逩灬. 提交于 2019-12-23 12:36:03
问题 I use the Anaconda Python distribution on Ubuntu linux and would like to use R magics in IPython notebooks. Is there a way to install rpy2 with the conda distribution and use my current default R installation at /usr/bin/R? My goal is to keep the current R installation as is without installing R or other R packages via conda. This response to a related question suggests using a recipe for doing so on mac, but doesn't work for me: conda skeleton pypi rpy2 conda build rpy2 conda install rpy2 -

“Error: Tried to guess R's HOME but no R command in the PATH”

耗尽温柔 提交于 2019-12-23 02:35:12
问题 "Error: Tried to guess R's HOME but no R command in the PATH" after runing [ rpy2-2.5.6]$ python setup.py install commands in my redhat server 回答1: Try to install libraries always with pip instead of messing around yourself with setup.py files. I run into the same error under windows 8, R Version 3.3.1 and Python 2.7, 32bit. The solution is easy but for this case the normal pip install rpy2 does not work. Instead try to use the Windows-Binaries you find them here: http://www.lfd.uci.edu/

Issue with rpy2 handling NA/missing value in dataframe from R to Python

爷,独闯天下 提交于 2019-12-22 18:31:51
问题 I've encounter a problem when using rpy2 package to transform dataframe saved in R to Python. import os os.environ['R_HOME'] = '/Library/Frameworks/R.framework/Resources' import rpy2.robjects as ro from rpy2.robjects import pandas2ri # define a trivial dataframe in R ro.r('n = c(1,2)') ro.r("b = c(NA,'def')") ro.r("temp_df = data.frame(n,b)") # the dataframe in R shows missing value in one cell as NA temp_rdf = ro.r('temp_df') print(temp_rdf) n b 1 1 <NA> 2 2 def # yet the transformed Python

Modify r object with rpy2

风格不统一 提交于 2019-12-22 18:23:27
问题 I'm trying to use rpy2 to use the DESeq2 R/Bioconductor package in python. I actually solved my problem while writing my question (using do_slots allows access to the r objects attributes), but I think the example might be useful for others, so here is how I do in R and how this translates in python: In R I can create a "DESeqDataSet" from two data frames as follows: counts_data <- read.table("long/path/to/file", header=TRUE, row.names="gene") head(counts_data) ## WT_RT_1 WT_RT_2 prg1_RT_1