ralhei / pyRserve

A python client for Rserve (network layer to remote R server)
Other
47 stars 13 forks source link

S4 support #14

Closed flying-sheep closed 7 years ago

flying-sheep commented 7 years ago

currently, the S4 data typecode isn’t supported. here a bit of info how they work:

S4 classes are simply data-less objects of a special type (S4SXP) with attributes.

a formal class definition (e.g. getClass('dgeMatrix').__C__dgeMatrix) contains data useful for validation (i.e. the types the attributes may take on and validation functions) and the class hierarchy.

attributes present in the class definition are called “slots” and can be accessed by slot() and the @ operator.

a NULL in a slot is represented by the name object `\001NULL\001` (since attributes can’t be NULL itself)


i propose we simply convert them to a class S4(dict) that has all the slots as dict entries. if users want the class metadata, they can call getClass or more specific functions in R, and when you send a S4(slot1=spam, slot2=eggs) from python to R, R will do the validation.

deserialization would be easy: just extract and convert the attributes, making sure to convert `\001NULL\001`None