rbartpackages.base.rproperty

rbartpackages.base.rproperty(meth, *, rname=None, wrap=None)[source]

Automatically implement a read-only property using the corresponding R field.

Unlike the attributes RObjectBase snapshots at initialization, the field is extracted from the R object at each access, so it tracks mutable objects such as reference-class instances.

Parameters:
  • meth (FunctionType) – A method in a subclass of RObjectBase. The original implementation is completely discarded.

  • rname (str | None, default: None) – The name of the field in R. If not specified, use the name of meth.

  • wrap (type[RObjectBase] | None, default: None) – A RObjectBase subclass to wrap the field with, instead of converting it to a Python value.

Returns:

property – A read-only property that extracts the field with R’s $ operator. NULL fields are exposed as None.

Examples

>>> class MyRObject(RObjectBase):
...     _rfuncname = 'mypackage::myfunction'
...     @partial(rproperty, rname='my.field')
...     def my_field(self):
...         ...