rpy2

Discrete Kolmogorov-Smirnov testing: getting wrong value when using rpy2 compared to pure R

喜欢而已 提交于 2019-12-06 15:24:38
问题 I am trying to use the dgof module from R, in Python 3 via rpy2 . I use it inside python as so: # import rpy2's package module import rpy2.robjects.packages as rpackages # Import R's utility package utils = rpackages.importr('utils') # Select a mirror for R packages utils.chooseCRANmirror(ind=1) # select the first mirror in the list # R vector of strings from rpy2.robjects.vectors import StrVector # Install R package name: 'dgof' (discrete goodness-of-fit) is what we're interested in if

Django - App crashing when using pandas2ri

依然范特西╮ 提交于 2019-12-06 13:31:27
I am implementing rpy2 code in Django and when I convert pandas dataframe into r dataframe my app starts crashing and giving error: Error: C stack usage 60820464 is too close to the limit otherwise app works fine as long as i don't convert. Is there any problem/mistake in my code? My code snippet: from .models import Values import pandas as pd from rpy2.robjects import pandas2ri pandas2ri.activate() def rpyset(request): filterdata = pd.DataFrame(list(Values.objects.all().values('val1','val2', 'val3', 'val4', 'val5', 'val6'))) r_dataframe = pandas2ri.py2ri(filterdata) # I want to pass r

Ipython notebook crash using rmagic extension

☆樱花仙子☆ 提交于 2019-12-06 11:32:03
问题 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:

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

筅森魡賤 提交于 2019-12-06 09:28:51
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-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DR

Pass list from python to R through rpy2

坚强是说给别人听的谎言 提交于 2019-12-06 07:18:38
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. Gabriel Posting my own answer based on the one given by lgautier since that one did not work as is. I also made it a bit

Modify r object with rpy2

拜拜、爱过 提交于 2019-12-06 06:27:13
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 prg1_RT_2 ## aap-1 406 311 41 95 ## aat-1 5 8 2 0 ## aat-2 1 1 0 0 ## aat-3 13 12 0 1 ## aat-4 6 6 2 3 ##

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

浪尽此生 提交于 2019-12-06 04:41:08
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 dataframe replace the missing value with a string temp_pydf = pandas2ri.ri2py(temp_rdf) print(temp_pydf

%load_ext rpy2.ipython Image not found error

非 Y 不嫁゛ 提交于 2019-12-06 02:56:12
I am trying to use the magic command in ipython, something I saw here: rpy2 slides I have done the following: import rpy2.ipython %load_ext rpy2.ipython But I get the following error: ImportError: dlopen(/Users/XXX/anaconda/lib/python2.7/site-packages/rpy2/rinterface/_rinterface.so, 2): Library not loaded: libicuuc.54.dylib Referenced from: /Users/XXX/anaconda/lib/python2.7/site-packages/rpy2/rinterface/_rinterface.so Reason: image not found Some relevant information: OS: MacOS Sierra Python: 2.7.12 iPython: IPython 5.1.0 rpy2: 2.8.3 Did the pip install singledispatch but the error still

rpy2, R and Ubuntu 12.04 - Invalid substring -fopenmp

﹥>﹥吖頭↗ 提交于 2019-12-05 23:57:49
What's the reason for the error when installing rpy2 on Ubuntu 12.04? easy_install rpy2 Searching for rpy2 Reading http://pypi.python.org/simple/rpy2/ Best match: rpy2 2.3.9 Downloading https://pypi.python.org/packages/source/r/rpy2/rpy2-2.3.9.tar.gz#md5=86851a56f637e7b87709eb2b91dc5075 Processing rpy2-2.3.9.tar.gz Running rpy2-2.3.9/setup.py -q bdist_egg --dist-dir /tmp/easy_install-DFDRi5/rpy2-2.3.9/egg-dist-tmp-7nyGO8 "/usr/lib/R/bin/R" CMD config --ldflags Invalid substring -fopenmp in string -Wl,--export-dynamic -fopenmp -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lrt -ldl -lm error: Setup

Migrating a logistic regression from R to rpy2

孤人 提交于 2019-12-05 20:15:45
I'm trying to use ryp2 to do a logistic regression. I managed to execute it, but don't know how to extract the coefficients and p-values from the result. I don't want to print the values on the screen bu create a function to use them independently. import rpy2.robjects as ro mydata = ro.r['data.frame'] read = ro.r['read.csv'] head = ro.r['head'] summary = ro.r['summary'] mydata = read("http://www.ats.ucla.edu/stat/data/binary.csv") #cabecalho = head(mydata) formula = 'admit ~ gre + gpa + rank' mylogit = ro.r.glm(formula=ro.r(formula), data=mydata,family=ro.r('binomial(link="logit")')) #What