Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object types for rpy2py_basic in rpy_classic #23

Closed
lgautier opened this issue Nov 13, 2009 · 6 comments
Closed

object types for rpy2py_basic in rpy_classic #23

lgautier opened this issue Nov 13, 2009 · 6 comments

Comments

@lgautier
Copy link
Member

Original report by Anonymous.


The object type LANGSXP needs to be added to the objects that the rpy2py_basic function can handle in rpy_classic

@lgautier
Copy link
Member Author

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


The question is how.
How does rpy convert a LANGSXP into a pure python object ?

@lgautier
Copy link
Member Author

Original comment by Anonymous.


It doesn't convert, it just leaves it as an R object. However, when rpy_classic runs across a LANGSXP it raises a Value Error:

File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/rpy2/rpy_classic.py", line 160, in rpy2py_basic
raise ValueError("Invalid type %i (%s) for 'obj'." %(obj.typeof, ri.str_typeint(obj.typeof)))
ValueError: Invalid type 6 (LANGSXP) for 'obj'.

I think the problem is that LANGSXP objects have a length attribute, and so they aren't being passed to the res = Robj(obj) command, but instead are being passed to the conversion commands which don't know what to do with it.

@lgautier
Copy link
Member Author

Original comment by Anonymous.


I tried the following modification of the rpy2py_basic function that seems to work (bold indicates my additions):
`
#!python

def rpy2py_basic(obj):
if hasattr(obj, 'len'):
if obj.typeof in [ri.INTSXP, ri.REALSXP, ri.CPLXSXP,
ri.LGLSXP, ri.STRSXP]:
res = [x for x in obj]
elif obj.typeof in [ri.VECSXP]:
res = [rpy2py(x) for x in obj]
elif obj.typeof in [ri.LANGSXP]:
res = Robj(obj)

else:
raise ValueError("Invalid type %i (%s) for 'obj'." %(obj.typeof, ri.str_typeint(obj.typeof)))
else:
res = Robj(obj)
return res

@lgautier
Copy link
Member Author

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


Bump!

@lgautier
Copy link
Member Author

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


The fix is now in the branch rpy2-2.1dev

@lgautier
Copy link
Member Author

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


Removing version: 2.1.0 (automated comment)

@lgautier lgautier transferred this issue from another repository Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant