myCat.matrix <- function(..., sep=", ") {
cat("A matrix:
");
cat(..., sep=sep);
cat("");
}
myCat.default <- function(..., sep=", ") {
cat(..., sep=sep);
cat("");
}
setGenericS3("myCat");
myCat(1:10);
mat <- matrix(1:10, ncol=5);
attr(mat, "class") <- "matrix"; # Has to be done as of [R] V1.4.0.
myCat(mat);Run the code above in your browser using DataLab