Skip to contents

Names a class that R8 did not declare: an S3 class, an implicit class such as "matrix" or "NULL", an S4 class, or an S7 class. It is a dispatched position of an impl of an R8 generic or trait, and a field type inside option(). A dispatched position matches an object whose class vector, as .class2() reports it, contains the class; the nearer the class is to the front of that vector, the more specific the impl. In implement(), impl(), r8method(), and r8next_impl(), a string is shorthand for host_class() of an S3 or implicit class, and an S4 class object, as methods::getClass() returns it, for host_class() of that S4 class.

Usage

host_class(class, package = "", system = c("s3", "s4", "implicit", "s7"))

Arguments

class

Character: The class name; or an S7 class object.

package

Character: The package that defines the class; "" for an S3 class of no package named and for an implicit class.

system

Character: The class system. "s3": a name in an object's class attribute. "implicit": a name that .class2() derives from an object without a class attribute, from its type and dim attribute: NULL, integer, double, numeric, character, logical, complex, raw, list, function, matrix, array, environment, name, or call; a string naming one of these is implicit. "s4": a class defined with methods::setClass(), which requires package; r8register() checks at load that the package defines an S4 class of that name. "s7": a class of S7::new_class(), with package the package that defines it, or "" for a class defined outside a package; an S7 class object given as class names its own name and package.

Value

An object of class r8_host_class, which is also a field type: option(host_class("lm")) declares a field that holds an object whose class vector contains "lm", host-only, absent from documents and from the content hash.

Details

An impl on a host class is declared by the package of the generic or trait, or by the package that package names.

Examples

op <- options(r8.namespace = "hosts")
shape_text <- generic("shape_text", params(x))
implement(shape_text, "data.frame") <- function(x) paste(nrow(x), "rows")
implement(shape_text, host_class("matrix")) <- function(x) {
  paste(nrow(x), "by", ncol(x))
}
shape_text(data.frame(a = 1:3))
#> [1] "3 rows"
shape_text(diag(2))
#> [1] "2 by 2"
field(option(host_class("lm")), context = TRUE)
#> <r8 field> optional object of class lm
#>   filled from the context
options(op)