1
votes

I got an error while creating a new method for a new class

> setClass("CIR", representation(PATH="numeric", GRID="numeric", PARAMS="numeric"));
[1] "CIR"
>
> setMethod("plot", signature(x="CIR"), ,
+ function(x) {
+ plot(slot(x,"GRID"),slot(x,"PATH"),type="l")
+ points(slot(x,"GRID"),slot(x,"PATH"),col="red",cex=0.5)
+ })
Error in as.environment(where) : invalid object for 'as.environment'

How can I solve it? Thanks!

1

1 Answers

2
votes

You have two commas at the end of the line containing setMethod, which means you inadvertently left definition blank and set where to a function. Try this instead:

setMethod("plot", signature(x="CIR"),
  function(x) {
  plot(slot(x,"GRID"),slot(x,"PATH"),type="l")
  points(slot(x,"GRID"),slot(x,"PATH"),col="red",cex=0.5)
})