Description Usage Arguments Details Value Examples
View source: R/create_s3_methods.R
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.
1 2 3 | create_s3_method(generic = NULL, object = NULL)
create_s3_print(fun, ...)
|
generic, object |
as described for |
fun |
Function to transform object before print
(probably |
... |
additional arguments passed to print method |
Don't forget to also create for example a data.frame method by
as.data.frame.xxx <- as.data.frame.vector
S3-method.
1 2 3 4 5 6 | 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])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.