require(graphics)
setClass("track",
representation(x="numeric", y="numeric"))
## First, with only one object as argument:
setMethod("plot", signature(x="track", y="missing"),
function(x, y, ...) plot(slot(x, "x"), slot(x, "y"), ...))
## Second, plot the data from the track on the y-axis against anything
## as the x data.
setMethod("plot", signature(y = "track"),
function(x, y, ...) plot(x, slot(y, "y"), ...))
setMethod("plot", "track",
function(x, y, ...) plot(slot(x, "y"), y, ...))
## Assuming the methods for plot
## are set up as in the example of help(setMethod),
## print (without definitions) the methods that involve class "track":
showMethods("plot", classes = "track")
# Function "plot":
# x = ANY, y = track
# x = track, y = missing
# x = track, y = ANY
require("Matrix")
showMethods("%*%")# many!
methods(class = "Matrix")# nothing
showMethods(class = "Matrix")# everything
showMethods(Matrix:::isDiagonal) # a non-exported genericif(no4 <- is.na(match("stats4", loadedNamespaces())))
loadNamespace("stats4")
showMethods(classes = "mle") # -> a method for show()
if(no4) unloadNamespace("stats4")
Run the code above in your browser using DataCamp Workspace