pyreadr icon indicating copy to clipboard operation
pyreadr copied to clipboard

error: The file contains an unrecognized object

Open rojinsafavi opened this issue 4 years ago • 7 comments

import pyreadr

result = pyreadr.read_r('infile.rds')

---------------------------------------------------------------------------
LibrdataError                             Traceback (most recent call last)
<ipython-input-46-82b33438231f> in <module>
      1 import pyreadr
      2 
----> 3 result = pyreadr.read_r('infile.rds')

/projects/sysbio/projects/rojin/anaconda3/envs/scvi/lib/python3.6/site-packages/pyreadr/pyreadr.py in read_r(path, use_objects, timezone)
     45     if not os.path.isfile(path):
     46         raise PyreadrError("File {0} does not exist!".format(path))
---> 47     parser.parse(path)
     48 
     49     result = OrderedDict()

/projects/sysbio/projects/rojin/anaconda3/envs/scvi/lib/python3.6/site-packages/pyreadr/librdata.pyx in pyreadr.librdata.Parser.parse()

/projects/sysbio/projects/rojin/anaconda3/envs/scvi/lib/python3.6/site-packages/pyreadr/librdata.pyx in pyreadr.librdata.Parser.parse()

LibrdataError: The file contains an unrecognized object

rojinsafavi avatar Oct 16 '20 20:10 rojinsafavi

From the Readme, known limitations section:

S4 Objects and probably other kind of objects, 
including those that depend on non base R 
packages (Bioconductor for example) cannot 
be read. The error code in this case is as follows:

"pyreadr.custom_errors.LibrdataError: 
The file contains an unrecognized object

ofajardo avatar Oct 16 '20 21:10 ofajardo

How to solve it? thank you @ofajardo

zznx avatar Nov 05 '20 08:11 zznx

No solution at the moment. The issue is tracked here: https://github.com/WizardMac/librdata/issues/16

ofajardo avatar Nov 05 '20 09:11 ofajardo

I have run into this same issue and as far as I can tell, my data has no S4 objects or any unusual object types. Any thoughts on what else could be the issue?

Anthony-C-Nguyen avatar May 05 '21 20:05 Anthony-C-Nguyen

Please share the file. If I cannot reproduce it I cannot debug.

ofajardo avatar May 05 '21 20:05 ofajardo

Unfortunately the data contains personal health information and cannot be shared. I have an alternative versions of the data (same object types) that does not run into issues. If I am able to create the a version with fake data that reproduces the issue I will share. Thanks.

Anthony-C-Nguyen avatar May 06 '21 01:05 Anthony-C-Nguyen

I think I was able to resolve the issue. Seems to have come down to two things. It had an issue with the object being type "data.frame". However, as a "data.table" "data.frame" I no longer had the error. However, after this was resolved, the kernel would always reset. I found that the data had factor variables with NA coded as a level. This seemed to cause the kernel to reset

Anthony-C-Nguyen avatar May 07 '21 15:05 Anthony-C-Nguyen