R objects

The class rpy2.robjects.RObject can represent any R object, although it will often be used for objects without any more specific representation in Python/rpy2 (such as Vector, functions.Function, Environment).

The class inherits from the lower-level rpy2.rinterface.Sexp and from rpy2.robjects.robject.RObjectMixin, the later defining higher-level methods for R objects to be shared by other higher-level representations of R objects.

class rpy2.robjects.robject.RObjectMixin[source]

Bases: ABC

Abstract class to provide methods common to all RObject instances.

r_repr()[source]

String representation for an object that can be directly evaluated as R code.

property rclass

R class for the object, stored as an R string vector.

When setting the rclass, the new value will be:

  • wrapped in a Python tuple if a string (the R class is a vector of strings, and this is made for convenience)

  • wrapped in a StrSexpVector

Note that when setting the class R may make a copy of the whole object (R is mostly a functional language). If this must be avoided, and if the number of parent classes before and after the change are compatible, the class name can be changed in-place by replacing vector elements.

property slots

Attributes of the underlying R object as a Python mapping.

The attributes can accessed and assigned by name (as if they were in a Python dict).

class rpy2.robjects.RObject(sexp: SupportsSEXP | SexpCapsule | UninitializedRCapsule)[source]

Bases: RObjectMixin, Sexp

Base class for all non-vector R objects.