File: setGenericS3.R

package info (click to toggle)
r-cran-r.methodss3 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 300 kB
  • sloc: sh: 12; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library("R.methodsS3")

message("TESTING: setGenericS3()...")

myCat.matrix <- function(..., sep=", ") {
  cat("A matrix:\n")
  cat(..., sep=sep)
  cat("\n")
}

myCat.default <- function(..., sep=", ") {
  cat(..., sep=sep)
  cat("\n")
}

setGenericS3("myCat")

myCat(1:10)
mat <- matrix(1:10, ncol=5)
myCat(mat)

setGenericS3("foo", validators=list(R.methodsS3:::rccValidateSetGenericS3))
setGenericS3("foo<-")

bar.default <- function(...) cat("bar.default\n")
bar <- function(...) cat("bar\n")
res <- tryCatch(setGenericS3("bar"), error = identity)
stopifnot(inherits(res, "error"))

print(getGenericS3("print"))


# Your definition will redefine bar() above to bar.default().
foobar <- function() print("foobar()")
setGenericS3("foobar")


# Cleanup
rm(list=ls())

message("TESTING: setGenericS3()...DONE")