1

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!

Tim
  • 1
  • 141
  • 372
  • 590

1 Answers1

2

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)
})
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418