prop_names: Property introspection

View source: R/property.R

prop_namesR Documentation

Property introspection

Description

  • prop_names(x) returns the names of the properties

  • prop_exists(x, "prop") returns TRUE and if only x has property prop.

  • prop_info() returns a data frame describing the properties of an S7 object or class, with one row per property.

Usage

prop_names(object)

prop_exists(object, name)

prop_info(object)

Arguments

object

Either an S7 object (an instance) or an S7 class.

name

A string giving the property of interest.

Value

  • prop_names() returns a character vector

  • prop_exists() returns a single TRUE or FALSE.

  • prop_info() returns a data frame with one row per property and the following columns:

    • name: a character vector of property names.

    • default: a list column of property defaults.

    • class: a character description of the class.

    • getter, setter, validator: logical vectors indicating whether the property has a getter, setter, or validator.

Examples

Horse := new_class(properties = list(
  name = class_character,
  colour = class_character,
  height = new_property(class_numeric, default = 15),
  age = new_property(
    class_numeric,
    validator = function(value) if (value < 0) "must be positive"
  ),
  now = new_property(getter = function(self) Sys.time())
))

prop_names(Horse)
prop_exists(Horse, "col")
prop_exists(Horse, "colour")
prop_info(Horse)

# All functions also work with objects, not just classes
lex <- Horse(colour = "bay", height = 15, name = "Lex", age = 3)
prop_names(lex)
prop_exists(lex, "age")

S7 documentation built on Nov. 19, 2026, 9:06 a.m.