# A function defines a new S3 class
# This function shouldn't really print anything to the R console when run
#' @export
myfun <- function(...){
...
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
print.mynewclass <- function(x,
digits = max(3, getOption("digits") - 3), ...){
...
invisible(x)
}
# summary method for objects of class mynewclass
#' @export
summary.mynewclass <- function(...){
...
class(output) <- "summary.mynewclass"
output
}
# print method for objects of class summary.mynewclass
#' @export
print.summary.mynewclass <- function(x,
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.summarymethods, defined as e.g.I recommend only using dots/periods in your function names if you are coding under the S3 class system