R: Template functions to generate basic S3 methods for new...

create_s3_method {rccmisc} | R Documentation

## Template functions to generate basic S3 methods for new classes

### Description

`create_s3_method` creates a method that applies `NextMethod` but that also keeps additional attributes (such as class). `create_s3_print` creates a print method.

### Usage

    create_s3_method(generic = NULL, object = NULL)

    create_s3_print(fun, ...)

### Arguments

`generic, object` | as described for `NextMethod`
`fun` | Function to transform object before print (probably `as.character`, `as.numeric` or similair).
`...` | additional arguments passed to print method

### Details

Don't forget to also create for example a data.frame method by

`as.data.frame.xxx <- as.data.frame.vector`

### Value

S3-method.

### Examples

    a <- structure(1:10, class = c("b", "numeric"))
    a[3] # Normal subsetting makes a loose its attributes
    `[.b` <- create_s3_method("[")
    print.b <- create_s3_print(as.numeric)
    a[3] # attributes preserved even if we can't see them
    str(a[3])

[Package rccmisc version 0.3.7 Index]