ID EN
Object & Attributes

UseMethod

R Base 3.6.2

R possesses a simple generic function mechanism which can be used for an object-oriented style of programming. Method dispatch takes place based on the class(es) of the first argument to the generic function or of the object supplied as an argument to UseMethod or NextMethod.

Syntax

R
UseMethod(generic, object)<p></p><p>NextMethod(generic = NULL, object = NULL, &#8230;)</p>

Arguments

Parameter Description
generic a character string naming a function (and not a built-in operator). Required for UseMethod.
object for UseMethod: an object whose class will determine the method to be dispatched. Defaults to the first argument of the enclosing function.
&#8230; further arguments to be passed to the next method.

Details

An R object is a data object which has a class attribute (and this can be tested by is.object). A class attribute is a character vector giving the names of the classes from which the object inherits. If the object does not have a class attribute, it has an implicit class. Matrices and arrays have class "matrix" or"array" followed by the class of the underlying vector. Most vectors have class the result of mode(x), except that integer vectors have class c("integer", "numeric") and real vectors have class c("double", "numeric"). When a function calling UseMethod("fun") is applied to an object with class attribute c("first", "second"), the system searches for a function called fun.first and, if it finds it, applies it to the object. If no such function is found a function called fun.second is

See Also

The draft ‘R Language Definition’. methods class getS3method is.object.