Add scipy2ri conversion for csr / coo sparse matrices
The R Matrix
package and scipy
both provide support for CSR, CSC and COO matrices, and yet rpy2
does not provide support to convert these. Are there any plans to provide such support?
Thanks!
Comments (9)


reporter Depending on how difficult it is I could be interested. I implemented the inverse conversion from reticulate. Do you mind sharing the skeleton?

How does it sound if I create a repos on Github under the rpy2 org ? (here: https://github.com/rpy2)

Here: https://github.com/rpy2/rpy2Matrix
The R package
Matrix
is somewhat complex with quite a fewS4
classes, so this only a hint at how much there is to be done to fully map it. A minimal viable mapping would not have to be exhaustive.Let me know what you think.

reporter Sounds good. The way we did this in reticulate is that any unmapped sparse matrix classes were first converted in R to a suitable matrix class (with a warning) and then converted back if possible.

reporter Silly question because I’m not super familiar with rpy2’s internals: where should I implement the actual conversion functions (equivalent of py2rpy and rpy2py)?

Modules
rpy2.robjects.numpy2ri
orrpy2.robjects.pandas2ri
are examples of converters.What a converter for
Matrix
could do is to check whether RS4
objects are RMatrix
objects can be converted to a correspondingscipy
object (or leave them as S4 objects otherwise), and the other waty around (whether ascipy
object can be converted to anrpy2
/R Matrix object, ideally as instance of subclasses ofrpy2.robjects.RS4
).So far the code in https://github.com/rpy2/rpy2Matrix is only building an
rpy2
class hierarchy for some of theMatrix
classes in the R packages. I should have time in few days to add a functioning mimal converter to build on. 
reporter Thanks! I’ll get to work on this in the coming weeks.

 changed status to resolved
There is an initial extension package
rpy2Matrix
at https://github.com/rpy2/rpy2Matrix. Additional comments, issues, code, etc... should probably go there.Reopen this if I missed anything.
 Log in to comment
There no immediate plans, but a first implementation in a independent package would make sense.
I just don’t have the bandwidth at the moment, but I am happy to help someone get started by setting up the initial skeleton and how to wire things to
rpy2
(conversion mechanisms, etc…)