[R] attempt at making a polygon class failed
Leeds, Mark (IED)
Mark.Leeds at morganstanley.com
Tue Aug 28 19:19:53 CEST 2007
I was reading a presentation of Professor Peng's and typed the
presentation code into R but I changed it to make plot.polygon a
separate function instread of defining the function in SetMethod itself
as he did. Is that the problem with the code below because
plot(p) just gives me zero. Thanks.
setClass("polygon", representation(x = "numeric",
y = "numeric"))
plot <- function(object)
{
return(0)
}
setGeneric("plot")
plot.polygon <- function(x, y, ...) {
xlim <- range(x at x)
ylim <- range(x at y)
plot(0,0, type = "n", xlim = xlim, ylim = ylim, ...)
xp <- c(x at x, x at x[1])
yp <- c(x at y, x at y[1])
lines(xp, yp)
}
setMethod("plot","polygon",plot.polygon)
p <- new("polygon", x = c(1,2,3,4), y = c(1,2,3,1))
plot(p)
--------------------------------------------------------
This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
More information about the R-help
mailing list