Git Product home page Git Product logo

rpy2's Introduction

Python -> R bridge

pypi Codecov GH Actions

The project's webpage is here: https://rpy2.github.io/

Installation

pip should work out of the box:

pip install rpy2

The package has optional depencies providing specific functionalities not otherwise required to use the rest of rpy2.

For example, to be able to run the unit tests:

pip install rpy2[test]

To install all optional dependencies (numpy, pandas, ipython), use:

pip install rpy2[all]

The package is known to compile on Linux, MacOSX (provided that developper tools are installed, and you are ready figure out how by yourself). The situation is currently a little more complicated on Windows. Check the issue tracker.

In case you find yourself with this source without any idea of what it takes to compile anything on your platform, try first

python setup.py install

Issues loading shared C libraries

Whenever R is in not installed in a system location, the system might not know where to find the R shared library.

If R is in the PATH, that is entering R on the command line successfully starts an R terminal, but rpy2 does not work because of missing C libraries, try the following before starting Python:

export LD_LIBRARY_PATH="$(python -m rpy2.situation LD_LIBRARY_PATH)":${LD_LIBRARY_PATH}

Documentation

Documentation is available either in the source tree (doc/), or online.

Testing

rpy2 uses pytest, with the plugin pytest-cov for code coverage. To test the package from the source tree, either to check and installation on your system or before submitting a pull request, do:

pytest tests/

For code coverage, do:

pytest --cov=rpy2.rinterface_lib \
       --cov=rpy2.rinterface \
       --cov=rpy2.ipython \
       --cov=rpy2.robject \
       tests

For more options, such as how to run specify tests, please refer to the pytest documentation.

License

RPy2 can be used under the terms of the GNU General Public License Version 2 or later (see the file gpl-2.0.txt). This is the very same license R itself is released under.

rpy2's People

Contributors

andportnoy avatar anntzer avatar bbbruce avatar breisfeld avatar ccwang002 avatar cgohlke avatar dalejung avatar davclark avatar gijzelaerr avatar grayver avatar isuruf avatar ixjlyons avatar jimcortes avatar joan-smith avatar joonro avatar justinshenk avatar kenahoo avatar krassowski avatar lgautier avatar matthewwardrop avatar mdeff avatar mkoeppe avatar mmagnuski avatar nedjwestern avatar njsmith avatar pablooliveira avatar paulmueller avatar takluyver avatar tikuma-lsuhsc avatar younik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpy2's Issues

conversion of named lists in rpy_classic

Original report by Anonymous.


In the old Rpy, when converting R lists to python, if the items in the list were named, then instead of converting to a python list, it would convert the list to a dictionary with the names as keys. That way, items in the list could be indexed by name. Currently rpy_classic does not do this, but it would be very helpful if it did.

support scale_linetype_manual please

Original report by John Owens (Bitbucket: jowens, GitHub: jowens).


(I note the docs now say use bitbucket for bugs, so reporting it here.)

rpy2 appears to support scale_colour_manual and scale_fill_manual, but not scale_shape_manual or scale_linetype_manual. Error message is:

AttributeError: 'module' object has no attribute 'scale_linetype_manual'

Any chance of getting those two into the current build?

rpy2.robjects.r.formula broken

Original report by Anonymous.


Setting a formula using rpy2.robjects.r.formula() call fails (though rpy2.robjects.Formula() calls work fine):

#!python

>>> import rpy2.robjects
>>> print rpy2.__version__
2.1.0rc
>>> rpy2.robjects.r.formula('y~x')
Error in parse(text = x) : unexpected '<' in "<"
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File
"/space/nsg/8/users/mypythonmodules/lib/python2.5/site-packages/rpy2/robjects/functions.py",
line 81, in __call__
     return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
   File
"/space/nsg/8/users/mypythonmodules/lib/python2.5/site-packages/rpy2/robjects/functions.py",
"/space/nsg/8/users/mypythonmodules/lib/python2.5/site-packages/rpy2/robjects/functions.py", line 36, in __call__
     res = conversion.ri2py(res)
   File
"/space/nsg/8/users/mypythonmodules/lib/python2.5/site-packages/rpy2/robjects/__init__.py", line 80, in default_ri2py
     res = Formula(o)
   File
"/space/nsg/8/users/mypythonmodules/lib/python2.5/site-packages/rpy2/robjects/__init__.py", line 190, in __init__
     env = environment)
rpy2.rinterface.RRuntimeError: Error in parse(text = x) : unexpected '<' in "<"

>>>

iterating lists from data.frame doesn't work right

Original report by Hari Krishna Dara (Bitbucket: haridsv, GitHub: haridsv).


I tried creating a simple data.frame with two columns and when I tried to iterate, I got the first column right, but not the second.

#!python

>>> df = r("data.frame(col1 = c(1, 2, 3), col2 = c('a', 'b', 'c'))")
>>> [i for i in df[1]]
[1, 2, 3]
>>> [i for i in df[0]]
[1.0, 2.0, 3.0]
>>> [i for i in df.colnames()]
['col1', 'col2']

I tried exactly the same in R console and indexing worked as expected:

#!R

> df = data.frame(col1 = c(1, 2, 3), col2 = c('a', 'b', 'c'))
> df[1]
  col1
1    1
2    2
3    3
> df[2]
  col2
1    a
2    b
3    c

I got the same result using the documented example:

#!python

>>> from rpy2 import robjects
>>> d = {'value': robjects.IntVector((1,2,3)), 'letter': robjects.StrVector(('x', 'y', 'z'))}
>>> dataf = robjects.r['data.frame'](**d)
>>> [i for i in dataf[0]]
[1, 2, 3]
>>> [i for i in dataf[1]]
[1, 2, 3]

I couldn't try using 2.1.0alpha3 because it wouldn't compile using Microsoft Visual C++ 2008 Express Edition (which is what I used so far for all the package that I built).

can't pickle rpy2.rinterface.RRuntimeError

Original report by Hari Krishna Dara (Bitbucket: haridsv, GitHub: haridsv).


I am trying to use multiprocessing module to delete R evaluation to a external processes. The result of evaluation is sent back via a multiprocessing.Queue, but if there is an exception in evaluation, the result is the exception object. The problem is that RRuntimeError class is not serializable using pickle module, since the name it returns is not fully qualified (says "rinterface.RRuntimeError"). If you try to use pickle.dumps(), this is the error you get:

PicklingError: Can't pickle <class 'rinterface.RRuntimeError'>: it's not found as rinterface.RRuntimeError

Is there a genuine reason for making RRuntimeError unfriendly to pickle?

FactorVector has no 'rx' attribute

Original report by Anonymous.


I've created a FactorVector and then I attempted to extract an item from it using R-style extraction, as suggested in the documentation. I received the following error, though:
AttributeError: 'FactorVector' object has no attribute 'rx'

build: rpy2 2.1.0beta2
OS: Ubuntu Karmic

rpy/rinterface/buffer.c:223: error: ‘readbufferproc’ undeclared here (not in a function)

Original report by Tru Huynh (Bitbucket: tru, GitHub: tru).


python 2.4 building of 2.1.0 version fails on CentOS-5 x86_64

[tru@liberte rpy2-2.1.0]$ python setup.py install --prefix=/tmp/a
running install
running build
running build_py
running build_ext
building 'rpy2.rinterface.rinterface' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fPIC -DR_INTERFACE_PTRS=1 -DHAVE_POSIX_SIGJMP=1 -DCSTACK_DEFNS=1 -DRIF_HAS_RSIGHAND=1 -Irpy/rinterface -I/usr/include/python2.4 -I/c5/shared/R/2.10.0/lib64/R/include -c rpy/rinterface/rinterface.c -o build/temp.linux-x86_64-2.4/rpy/rinterface/rinterface.o -L/c5/shared/R/2.10.0/lib64/R/lib -lR -L/c5/shared/R/2.10.0/lib64/R/lib -lRlapack -L/c5/shared/R/2.10.0/lib64/R/lib -lRblas
In file included from rpy/rinterface/rinterface.c:103:
rpy/rinterface/buffer.c:223: error: ‘readbufferproc’ undeclared here (not in a function)
rpy/rinterface/buffer.c:223: error: expected ‘}’ before ‘VectorSexp_getreadbuf’
In file included from rpy/rinterface/rinterface.c:105:
rpy/rinterface/sequence.c: In function ‘VectorSexp_ass_slice’:
rpy/rinterface/sequence.c:447: warning: unused variable ‘sexp_item’
rpy/rinterface/sequence.c:447: warning: unused variable ‘tmp’
rpy/rinterface/sequence.c:446: warning: unused variable ‘vs’
rpy/rinterface/sequence.c:386: warning: unused variable ‘self_typeof’
rpy/rinterface/sequence.c: At top level:
rpy/rinterface/sequence.c:515: error: ‘ssizessizeargfunc’ undeclared here (not in a function)
rpy/rinterface/sequence.c:515: error: expected ‘}’ before ‘VectorSexp_slice’
rpy/rinterface/rinterface.c: In function ‘EmbeddedR_end’:
rpy/rinterface/rinterface.c:1112: warning: unused variable ‘str’
error: command 'gcc' failed with exit status 1

segmentation fault in test suite

Original report by Anonymous.


Mac OS X 10.6.2
Python 2.5.4 -- EPD 5.1.1
R version 2.10.0 (2009-10-26)

$ python

Python 2.6.4 (r264:75706, Nov 18 2009, 19:07:51)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import rpy2
 >>> rpy2.__version__
'2.1.0dev'
 >>> import rpy2.tests
 >>> import unittest
 >>> tr = unittest.TextTestRunner(verbosity = 5)
 >>> suite = rpy2.tests.suite()
 >>> tr.run(suite)
testDo_slot (rpy2.robjects.tests.testRObject.RObjectTestCase) ... ok
testNew (rpy2.robjects.tests.testRObject.RObjectTestCase) ... ok
testR_repr (rpy2.robjects.tests.testRObject.RObjectTestCase) ... ok
testRclass (rpy2.robjects.tests.testRObject.RObjectTestCase) ... ok
testRclass_set (rpy2.robjects.tests.testRObject.RObjectTestCase) ... ok
testStr (rpy2.robjects.tests.testRObject.RObjectTestCase) ... ok
testPickle (rpy2.robjects.tests.testRObject.RObjectPicklingTestCase) ... Segmentation fault 

setup.py fails on Windows

Original report by Anonymous.


Lines

include_dirs = get_rconfig(r_home, '--cppflags')[0].split()

and

            extra_link_args = get_rconfig(r_home, '--ldflags') +\
                get_rconfig(r_home, 'LAPACK_LIBS', 
                            allow_empty=True) +\
                            get_rconfig(r_home, 'BLAS_LIBS')

fail on Windows XP using R 2.9.0 with the message

Exception: "c:\PROGRA~1\R\R-29~1.0\bin\R" CMD config --cppflags
returned

rpy2 -> numpy mangles arrays

Original report by Anonymous.


Hi.

My project involves generating models and predictions in rpy2, and analyzing them in python. One step of this is to bring a 3-dimensional array of predictions (lives in R as an RArray) into python as a numpy array. Rpy2-2.0.8 did this fine, but 2.1.3 (got it via easy_install on 06/14/2010) doesn't.

The shape of the resulting array is correct, but the values look transposed - it's hard to describe. A simple example:

RArray:
1 2
3 4
5 6
7 8

when copied into python as a numpy array looks like:

1 2
2 3
3 4
4 5

my code looks like this:

import rpy2.robjects as rob

import numpy as np

r = rob.r

params = {'object' : model.model, 'newdata' : validation_frame}

p = r.predict(**params)

predictions = np.array(p)

OK, that's all!

Lots of png files missing when building docs

Original report by John Owens (Bitbucket: jowens, GitHub: jowens).


I'm building from the hg trunk (tip?) and many png files are missing. Not sure why; hopefully this list is useful. Using Sphinx v0.6.2 on OS X (on python2.5). 2.6's Sphinx actually crashes; I've reported that bug for Sphinx.

#!text

! Package pdftex.def Error: File `_static/graphics_ggplot2_smoothbycylwithcolou
! Package pdftex.def Error: File `_static/graphics_lattice_xyplot_1.png' not fo
! Package pdftex.def Error: File `_static/graphics_lattice_xyplot_2.png' not fo
! Package pdftex.def Error: File `_static/graphics_lattice_xyplot_3.png' not fo
! Package pdftex.def Error: File `_static/graphics_ggplot2mtcars.png' not found
! Package pdftex.def Error: File `_static/graphics_ggplot2mtcarscolcyl.png' not
! Package pdftex.def Error: File `_static/graphics_ggplot2aescolsize.png' not f
! Package pdftex.def Error: File `_static/graphics_ggplot2geomhistogram.png' no
! Package pdftex.def Error: File `_static/graphics_ggplot2geomhistogramfillcyl.
! Package pdftex.def Error: File `_static/graphics_ggplot2geomfreqpolyfillcyl.p
! Package pdftex.def Error: File `_static/graphics_ggplot2geombin2d.png' not fo
! Package pdftex.def Error: File `_static/graphics_ggplot2geomboxplot.png' not 
! Package pdftex.def Error: File `_static/graphics_ggplot2aescolboxplot.png' no
! Package pdftex.def Error: File `_static/graphics_ggplot2addsmooth.png' not fo
! Package pdftex.def Error: File `_static/graphics_ggplot2addsmoothmethods.png'
! Package pdftex.def Error: File `_static/graphics_ggplot2smoothbycyl.png' not 
! Package pdftex.def Error: File `_static/graphics_ggplot2_smoothbycylwithcolou
! Package pdftex.def Error: File `_static/graphics_ggplot2geompointandrug.png' 
! Package pdftex.def Error: File `_static/graphics_ggplot2geompointdensity2d.pn
! Package pdftex.def Error: File `_static/graphics_ggplot2smoothbycylfacetcyl.p
! Package pdftex.def Error: File `_static/graphics_ggplot2histogramfacetcyl.png
! Package pdftex.def Error: File `_static/graphics_ggplot2_qplot_4.png' not fou
! Package pdftex.def Error: File `_static/graphics_ggplot2_qplot_5.png' not fou
! Package pdftex.def Error: File `_static/graphics_ggplot2smoothblue.png' not f

Build fails on Mac OSX

Original report by Dane Springmeyer (Bitbucket: springmeyer, GitHub: springmeyer).


With latest rpy2 clone and latest R Framework the build fails

Here is my gcc version:

gcc -v
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5465)



#!sh
$ sudo python setup.py install
running install
running build
running build_py
running build_ext
building 'rpy2.rinterface.rinterface' extension
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe -DR_INTERFACE_PTRS=1 -DCSTACK_DEFNS=1 -DRIF_HAS_RSIGHAND=1 -Irpy/rinterface -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -c rpy/rinterface/array.c -o build/temp.macosx-10.5-i386-2.5/rpy/rinterface/array.o -F/Library/Frameworks/R.framework/.. -framework R -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRlapack -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRblas
cc1: error: unrecognized command line option "-framework R"
cc1: error: unrecognized command line option "-framework R"
lipo: can't open input file: /var/tmp//ccssueN7.out (No such file or directory)
error: command 'gcc' failed with exit status 1

Environment.__setitem__ and conversion.py2ri

Original report by Laurent Gautier (Bitbucket: lgautier, GitHub: lgautier).


Conversion from numpy does not appear to work when assigning items to an environment

#!python

import numpy as np
import rpy2.robjects as ro
import rpy2.robjects.numpy2ri 

x = np.arange(-10., 10., 0.1)

ro.globalenv["x"] = x

(reported by Christian Marquardt)

Support using "!" through a function

Original report by Anonymous.


I would like to use the R code

base.subset(df, !is.na(column_name))

but although there is a binding to base.is_na, there is no way of negating it. My workaround was to do this

not_is_na = robjects.r('function(x) !is.na(x)')

but it would be nice to be able to do this through a function call

r.not_(base.is_na(...))

patch to fix build on win32

Original report by Anonymous.


This patches fixes various issues when compiling RPy2 on Win32:

  • Rinterface.h is not present
  • R.dll is in RHOME/bin and not RHOME/lib
  • DLL imports are not compile-time constants
  • RIF_HAS_RSIGHAND and CSTACK_DEFNS shouldn't be defined

My setup: default R for Windows installation, Python 2.5, MinGW32

segfault on linux 64bit

Original report by Laurent Gautier (Bitbucket: lgautier, GitHub: lgautier).


Using SexpIntVector derived objects (matrix of integers, etc...) causes
sudden termination of the Python process (segfault).

The change <<changeset 6e11ab9f0832>> appears to address some of the issue, but still be incomplete.

Post here hints, help, or patches if you have any.

rpy2 2.1.0beta2 + Ubuntu Karmic -> libR.so not found

Original report by Anonymous.


I uninstalled rpy2 2.0.8 (installed via easy_installed) and I installed rpy2 2.1.0beta2 from source. Everything built and installed without problems. Attempting to import the package fails with the libR.so error described in the FAQ section. R was installed via the CRAN Ubuntu repository (Karmic)

libR.so is located in /usr/lib/R/lib and /usr/lib/R is correctly returned by the R RHOME command. Inspecting the setup.py build output shows that this folder is being properly indicated via the -L flag for gcc; for a bit of redundancy, explicitly passing this folder to the build process does not alleviate the problem.

Upon switching back to version 2.0.8, the error disappears. I managed to find a .deb for an earlier 2.1.0 alpha build. Installing via this .deb (after uninstalling any other version, of course), resulted in the same libR.so error.

I was able to fix the problem by creating a link to libR.so in /usr/local/lib, as suggested in the FAQ. I'm reporting this as a bug, though, since I only have this problem with 2.1.0 and not with any earlier versions.

as_py function in rpy_classic

Original report by Anonymous.


I'm working with a script that was originally written for rpy, trying to adapt it to work with rpy2. When I try to use the function as_py I get the following error message:

Traceback (most recent call last):
File "<pyshell#199>", line 1, in
fit_obj.final_parameters = fit_obj.as_py()['coefficients']
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/rpy2/rpy_classic.py", line 238, in as_py
res = rpy2py(self, mode)
NameError: global name 'self' is not defined

I've gone over my script in about as much detail as possible. Either the usage of as_py in the script is incorrect, which would only be if there is a difference in usage between rpy and rpy_classic, or there's something fishy with the rpy_classic source code. Any insight or advice would be greatly appreciated.

Refcount issues in rinterface.c

Original report by hogend (Bitbucket: hogend, GitHub: hogend).


rinterface.c has a number of issues:

INCREF/DECREF Py_True generates compiler warnings: type-punned pointer-related

Py_False refcount is increased/decreased but this is not correct if an actual argument is supplied

PyDict_SetItemString increases refcounts itself

It is not necessary to use refcounting in a function, unless the object's scope is beyond that of the function

The attached diff against trunk corrects these issues (and a small logic optimisation)

rebind SEXP

Original report by Laurent Gautier (Bitbucket: lgautier, GitHub: lgautier).


Being able to rebind the underlying R SEXP a Python class defined in rpy2.rinterface is associated with would be helpful.

(note to self: I must have started that some months ago, check what is the status).

readline, free() invalid pointer and interfactive python freeze

Original report by Laurent Gautier (Bitbucket: lgautier, GitHub: lgautier).


Joseph Xu reported:

Hi:

I've just started using rpy2, and am running into a strange crash that
involves the readline module. The attached test case should
sufficiently explain the problem. If you run it you should see
something like

*** glibc detected *** python: free(): invalid pointer: 0xb79c6840 ***

and the terminal will stop responding.

I'm using python version 2.6.2 and rpy2 version 2.0.4 on Arch Linux.

Compile error in array.c (VC++ 2008, R 2.9.0)

Original report by Anonymous.


Compiling in windows against R 2.9.0 using VC++ 2008 results in the following:

c:\OpenSource\ryp2\rpy2\rpy\rinterface\rpy_rinterface.h(19) : warning C4114: same type qualifier used more than once
c:\OpenSource\ryp2\rpy2\rpy\rinterface\rpy_rinterface.h(20) : warning C4114: same type qualifier used more than once
rpy\rinterface\array.c(115) : error C2275: 'PyArrayInterface' : illegal use of this type as an expression
        rpy\rinterface\array.c(27) : see declaration of 'PyArrayInterface'
rpy\rinterface\array.c(115) : error C2065: 'inter' : undeclared identifier
rpy\rinterface\array.c(116) : error C2143: syntax error : missing ';' before 'type'
rpy\rinterface\array.c(117) : error C2065: 'typekind' : undeclared identifier
rpy\rinterface\array.c(121) : warning C4047: '=' : 'int' differs in levels of indirection from 'PyArrayInterface *'
rpy\rinterface\array.c(125) : error C2143: syntax error : missing ';' before 'type'
rpy\rinterface\array.c(126) : error C2143: syntax error : missing ';' before 'type'
rpy\rinterface\array.c(127) : error C2223: left of '->version' must point to struct/union
rpy\rinterface\array.c(128) : error C2223: left of '->nd' must point to struct/union
rpy\rinterface\array.c(128) : error C2065: 'nd' : undeclared identifier
rpy\rinterface\array.c(129) : error C2223: left of '->typekind' must point to struct/union
rpy\rinterface\array.c(130) : error C2223: left of '->itemsize' must point to struct/union
rpy\rinterface\array.c(131) : error C2223: left of '->flags' must point to struct/union
rpy\rinterface\array.c(132) : error C2223: left of '->shape' must point to struct/union
rpy\rinterface\array.c(133) : error C2223: left of '->shape' must point to struct/union
rpy\rinterface\array.c(133) : warning C4047: 'function' : 'Py_intptr_t *' differs in levels of indirection from 'int'
rpy\rinterface\array.c(133) : error C2198: 'sexp_shape' : too few arguments for call through pointer-to-function
rpy\rinterface\array.c(134) : error C2223: left of '->strides' must point to struct/union
rpy\rinterface\array.c(134) : error C2223: left of '->shape' must point to struct/union
rpy\rinterface\array.c(135) : error C2275: 'Py_intptr_t' : illegal use of this type as an expression
        c:\Python25\include\pyport.h(90) : see declaration of 'Py_intptr_t'
rpy\rinterface\array.c(135) : error C2146: syntax error : missing ';' before identifier 'stride'
rpy\rinterface\array.c(135) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
rpy\rinterface\array.c(135) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
rpy\rinterface\array.c(135) : error C2143: syntax error : missing ';' before 'identifier'
rpy\rinterface\array.c(135) : error C2065: 'stride' : undeclared identifier
rpy\rinterface\array.c(135) : error C2223: left of '->itemsize' must point to struct/union
rpy\rinterface\array.c(136) : error C2223: left of '->strides' must point to struct/union
rpy\rinterface\array.c(137) : error C2065: 'i' : undeclared identifier
rpy\rinterface\array.c(138) : error C2223: left of '->shape' must point to struct/union
rpy\rinterface\array.c(139) : error C2223: left of '->strides' must point to struct/union
rpy\rinterface\array.c(141) : error C2223: left of '->data' must point to struct/union
rpy\rinterface\array.c(142) : error C2223: left of '->data' must point to struct/union
rpy\rinterface\array.c(147) : warning C4022: 'PyCObject_FromVoidPtrAndDesc' : pointer mismatch for actual parameter 1
error: command '"c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe"' failed with exit status 2

rinterface.set_writeconsole() doesn't work

Original report by irha (Bitbucket: irha, GitHub: irha).


I installed rpy2-2.1.0a04072009.win32-py2.6.msi and tried the below:

>>> from rpy2.robjects import r
>>> from rpy2 import rinterface
>>> r('print("hi from R")')
[1] "hi from R"
<StrVector - Python:0x013A1580 / R:0x01B1A868>
>>> def r_print(msg):
...   print "R: %s" % msg
...
>>> rinterface.set_writeconsole(r_print)
>>> r('print("hi from R")')
[1] "hi from R"
<StrVector - Python:0x013AA6C0 / R:0x01B15C40>
>>>

As you can see, the r_print() python function didn't get called.

False == NA_Logical

Original report by Hari Krishna Dara (Bitbucket: haridsv, GitHub: haridsv).


I found that "False == NA_Logical" returns True, so you can't distinguish an NA value from that of a real FALSE. As a workaround I am further checking the type of object, but it shouldn't be required.

crash when calling 'ipython <some_script.py>'

Original report by Laurent Gautier (Bitbucket: lgautier, GitHub: lgautier).


When calling on the command line:

ipython <some_script.py>

ends on a
*** glibc detected *** /usr/bin/python: free(): invalid pointer
and a complimentary backtrace and memory map

On the other hand, doing

ipython
[let ipython start]
%run <some_script.py>

runs fine.

Replacing elements in a R list

Original report by Laurent Gautier (Bitbucket: lgautier, GitHub: lgautier).


Replacing elements in a R list appears broken:

#!python

import rpy2.robjects as ro
dataf = ro.vectors.DataFrame({'a':1, 'b':2})
# triggers an error
dataf[1] = ro.IntVector((8, ))

# works
data[1][0] = 8

sanity checks in setup.py too conservative

Original report by Michael Kuhn (Bitbucket: mkuhn, GitHub: mkuhn).


According to the R documentation, it is possible to specify just a file path for BLAS_LIBS: "If the value is not obviously a linker command (starting with a dash or giving the path to a library), it is prefixed by ‘-l’"

http://cran.r-project.org/doc/manuals/R-admin.html#index-BLAS_005fLIBS-72

Therefore, setup.py build failed for me thus:

Exception: "/apps/cellnet/R-2.11.0/lib64/R/bin/R" CMD config BLAS_LIBS
returned
/apps/cellnet/GotoBLAS/libgoto_core2p-r1.26.so

Patching setup.py to prepend an "-l" in this case worked.

LookupError: 'show' not found

Original report by sycomore (Bitbucket: sycomore, GitHub: sycomore).


Hello,
I have not been able to start rpy2 2.1.3 (see below error).
with R 2.11.1, Ubuntu 9.04 and python 2.6.2.
I have tried with compiling R from source (with --enable-shlib) and got the same error.
Is working fine on the same machine with R.2.9.2.

Any idea?
Thanks a lot.

Erreur dans identical(env, as.environment(i)) :
5 arguments passés à .Internal(identical) qui en exige 2

LookupError Traceback (most recent call last)

/home/raphael/ in ()

/usr/local/src/sage-4.1.2-linux-Ubuntu_9.04-i686-Linux/local/lib/python2.6/site-packages/rpy2/robjects/init.py in ()
17 import conversion
18
---> 19 from rpy2.robjects.robject import RObjectMixin, RObject
20 from rpy2.robjects.methods import RS4
21 from rpy2.robjects.vectors import *

/usr/local/src/sage-4.1.2-linux-Ubuntu_9.04-i686-Linux/local/lib/python2.6/site-packages/rpy2/robjects/robject.py in ()
7 import conversion
8
----> 9 class RObjectMixin(object):
10 """ Class to provide methods common to all RObject instances """
11 _name = None

/usr/local/src/sage-4.1.2-linux-Ubuntu_9.04-i686-Linux/local/lib/python2.6/site-packages/rpy2/robjects/robject.py in RObjectMixin()
20 __rclass = rpy2.rinterface.baseenv.get("class")
21 __rclass_set = rpy2.rinterface.baseenv.get("class<-")
---> 22 __show = rpy2.rinterface.baseenv.get("show")
23
24 def str(self):

LookupError: 'show' not found

graphical parameter names

Original report by Anonymous.


In the old rpy, when making calls to R graphical functions such as "par", parameter names that contained dots (such as cex.axis and col.axis) could be read by rpy if the dot were replaced by an underscore. In rpy2, this conversion does not work for calls to the R function "par". For instance:

#!python

 r.par(cex_axis=1.0)
Warning message:
In function (..., no.readonly = FALSE)  :
  "cex_axis" is not a graphical parameter

However, the dot-to-underscore conversion appears to work fine for arguments of other graphical functions, such as the pt.bg argument for the function "legend". Therefore, it ought to be possible to make it work for the "par" function as well.

segfault when calling robjects.r.table()

Original report by Laurent Gautier (Bitbucket: lgautier, GitHub: lgautier).


Bug report from Kylee Kim

#---

Hi,

I am getting segmentation fault error for robjects.r.table() and trying to understand why this happens.
Here is simplified example.

import rpy2.robjects as robjects
r = robjects.r
mylist = ['a', 'a', 'b', 'd', 'b']
myNumList = [1,2,3,4]

print robjects.IntVector(myNumList)

#>>> print robjects.IntVector(myNumList)
#[1] 1 2 3 4

print robjects.StrVector(mylist)

#>>> print robjects.StrVector(mylist)
#[1] "a" "a" "b" "d" "b"

print r.factor(robjects.StrVector(mylist))

#>>> print r.factor(robjects.StrVector(mylist))
#[1] a a b d b
#Levels: a b d

Both of the following produce a segmentation fault error.

r.table(robjects.StrVector(mylist))
r.table(r.factor(robjects.StrVector(mylist)))

I want to pass output of r.table into r.barplot.

r.barplot(r.table(robjects.StrVector(mylist)))

My environments are:
Python 2.4.1

R version 2.7.1 (2008-06-23)

Any advise on usage of r.table() and r.barplot() is much appreciated.

Thanks in advance,
Kylee

p.s. here are some corresponding R outputs.

mylist = c('a', 'a', 'b', 'd', 'b')
mylist
[1] "a" "a" "b" "d" "b"
table(mylist)
mylist
a b d
2 2 1
barplot(table(mylist))

memory leak when calling R functions with a python list or numpy array as argument

Original report by Anonymous.


Memory is allocated and lost every time an R function is called from python with a list or a numpy array as an argument. The following code shows this behaviour:

#!python

import rpy2.robjects
import gc, sys

f = rpy2.robjects.r('function(x) { return(NA); }')

x = range(1234)

print 'check process mem usage, then press enter'
# s/b about 17MB on a 32-bit OS, about 27MB on a 64-bit OS
sys.stdin.readline()

for i in range(123):
    f(x)
    gc.collect()

del x
del f
gc.collect()

print 'check process mem usage again, then press enter'
# about 135MB on a 32-bit OS, about 263MB on a 64-bit OS
sys.stdin.readline()

Tested on:

  • rpy2 2.1.0beta2
  • python 2.5.2
  • R 2.9.2
  • Ubuntu 8.04, both 32- and 64-bit versions

getting python coredump when i use NA_real on 2.1.0

Original report by John Owens (Bitbucket: jowens, GitHub: jowens).


Greetings, just installed rpy2 2.1.0 on python 2.6 on macports. I had 2.1.0rc running on python 2.5 earlier and this code worked; however with the release it does not.

The python code is simple:

#!/usr/bin/env python2.6
import rpy2.robjects as ro

x = []
y = []
x.append(1.0)
x.append(2.0)
y.append(3.0)
y.append(ro.NA_real)

dataf = ro.DataFrame( {'x': ro.FloatVector(x),
                       'y': ro.FloatVector(y),
                       } )

with the output:

$ ./rpy-example.py 
getsegcount
Segmentation fault

It's the NA_real that's the problem.

Here's the version info:

$ pwd
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/rpy2
$ cat __init__.py
__version_vector__ = ((2,1,0), '')

__version__ = '.'.join([str(x) for x in __version_vector__[0]]) + \
              '' + __version_vector__[1]
$ python2.6 --version
Python 2.6.5

please include limits control in ggplot2 binding

Original report by Anonymous.


Seems to work with:

class Limits(GBaseObject):
   _constructor = ggplot2_env['limits']
limits = Limits.new

class XLim(GBaseObject):
   _constructor = ggplot2_env['xlim']
xlim = XLim.new

class YLim(GBaseObject):
   _constructor = ggplot2_env['ylim']
ylim = YLim.new

numpy.recarray as DataFrame

Original report by Anonymous.


It seems natural to expect some sort of easy conversion between numpy record arrays and R data frames, considering that both are semantically tables with named columns. I do not know if the conversion can be carried out w/o making a copy (numpy seems to always store "records" and compact tuples - R probably stores by columns?).

Creating Data frames from Tagged lists

Original report by Anonymous.


When I attempt to create an R Data frame from a tagged list, I obtain the following error:

Traceback (most recent call last):
File "<pyshell#51>", line 1, in
baseNameSpaceEnv["data.frame"]
NameError: name 'baseNameSpaceEnv' is not defined

Distutils 'clean' doesn't work

Original report by jergosh (Bitbucket: jergosh, GitHub: jergosh).


Running 'python setup.py clean' doesn't delete the ./build tree. This causes issues e. g. after installing a new version of R (the C extensions don't get rebuilt and point to symbols in the previous version of R).

The problem may be on the side of distutils.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.