I've been experimenting a lot with S4 classes lately, and it pains me to restart R to clear all class definitions and custom methods from my workspace. Obviously rm(list=ls(all.names=TRUE)) useless. I could manually delete all the classes and methods individually by writing the lines one by one, but I'm sure there will be an easier way.
An example of a demonstration of 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 removing everything with rm() :
rm(list=ls(all.names=TRUE))
However, the class definition and user 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 deleted using rm , but the method referencing mySlot() remained. I would like to know how to remove all classes and all user methods in one fell swoop.
source share