# A function defines a new S3 class
# This function shouldn't really print anything to the R console when run
#' @export
<- function(...){
myfun
...class(output) <- "mynewclass"
# alternatively given objects can have multiple classes,
# append your new class to any existing classes
# class(output) <- append("mynewclass", class(output))
output
}
# print method for objects of class mynewclass
#' @export
<- function(x,
print.mynewclass digits = max(3, getOption("digits") - 3), ...){
...invisible(x)
}
# summary method for objects of class mynewclass
#' @export
<- function(...){
summary.mynewclass
...class(output) <- "summary.mynewclass"
output
}
# print method for objects of class summary.mynewclass
#' @export
<- function(x,
print.summary.mynewclass digits = max(3, getOption("digits") - 3),...){
...invisible(x)
}
4 Classes
Use classes for your functions (S3 easiest system; S4, RC)
Under S3 your class probably needs
print
,summary
,print.summary
methods, defined as e.g.I recommend only using dots/periods in your function names if you are coding under the S3 class system