I've been experimenting a lot with S4 classes lately, and it is a pain to restart R in order to clear all class definitions and custom methods from my workspace. Obviously rm(list=ls(all.names=TRUE))
is of no use. I could manually remove all classes and methods individually by writing lines one-by-one, but I'm sure there's got to be an easier way.
An example showcasing my problem:
.myClass <- setClass("myClass", representation=representation(mySlot="numeric"))
mySlot <- function(x) x@mySlot
setMethod("[", signature=c("myClass", "numeric", "missing"), function(x, i, j, ...) {
initialize(x, mySlot=mySlot(x)[i])
})
Try to remove everything with rm()
:
rm(list=ls(all.names=TRUE))
However, the class definition and custom method are still present:
> x <- new("myClass", mySlot=1:4)
> x[1]
Error in x[1] : could not find function "mySlot"
Since mySlot()
was an object it was removed with rm
, but the method referencing mySlot()
remained. I'd like to know how to remove all classes and all custom methods in one fell swoop.