Skip to contents

Methods are validated by S7 on isolated tables before registration is published. Method bindings and the implementation record are published together; a publication error restores the touched bindings. Aliases for the same generic must supply identical implementation functions.

Usage

trait_methods(trait, inherited = TRUE)

impl_trait(
  trait,
  class,
  methods = list(),
  assoc_types = list(),
  assoc_consts = list(),
  replace = FALSE
)

trait_report(x, trait)

has_trait(x, trait)

assert_trait(x, trait, arg = deparse(substitute(x)))

trait_call(trait, method, x, ...)

trait_assoc_type(trait, x, name)

trait_assoc_const(trait, x, name)

Arguments

trait

A trait created by new_trait().

inherited

Include inherited methods from supertraits?

class

A concrete S7 class, S3 class wrapper, S4 class, or base class wrapper. Register union members separately. Dispatch wildcards (class_any and class_missing) are not concrete targets.

methods

Named list of method implementations. Omitted trait methods use their default implementation when one is available.

assoc_types

Named list of associated type values.

assoc_consts

Named list of associated constant values.

replace

Replace an existing implementation record and silence warnings about visible S7 methods?

x

An S7, S3, S4 or supported base-class object, or its class descriptor.

arg

Name to use in error messages.

method

Method name within the trait.

...

Additional arguments passed to the S7 generic.

name

Associated item name.

Value

trait_methods() returns a named list of trait_method() objects. impl_trait() returns the stored implementation record, invisibly. trait_report() returns a one-row data frame. has_trait() returns a single logical value. assert_trait() returns x, unchanged. trait_call() returns the result of the underlying S7 generic. trait_assoc_type() and trait_assoc_const() return the stored associated item value.