vnmabus / rdata

Reader of R datasets in .rda format, in Python
https://rdata.readthedocs.io
MIT License
40 stars 2 forks source link

Data frames: include rownames as column (or pandas index) #14

Closed deeenes closed 2 years ago

deeenes commented 2 years ago

Hi @vnmabus,

Your package is super useful for me when parsing R objects in Python. However I have to patch it to extract the row names of data frames or names of lists: https://github.com/saezlab/pypath/blob/d3d7e9d0602a6b11496243c390f38edb9552714e/src/pypath/inputs/rdata.py#L26 Then I use this function to add the row names as a data frame column (or it could be the index, matter of preference): https://github.com/saezlab/pypath/blob/d3d7e9d0602a6b11496243c390f38edb9552714e/src/pypath/inputs/cellchatdb.py#L70

I am not very familiar with R objects, have no idea if my ugly hack works for all of them. But maybe you could easily integrate this functionality into your package, so it could become more robust and accessible.

vnmabus commented 2 years ago

Ok, this one was easy to implement. BTW, this package allows users to provide their own constructors for custom R classes (see for example how it is being done in the Navis project: https://github.com/navis-org/navis/blob/608000f8fad5baa6408398b5af13dee3dba078cc/navis/io/rda_io.py). You could have created a custom constructor for "data.frame" without resorting to such hacks. That said, I agree that this functionality is useful for everyone.

vnmabus commented 2 years ago

I have released a new version (0.6) including this change. Tell me if it works for you.