[R] setGeneric(rm)

Marcos Aurélio Carrero marcos at est.ufpr.br
Fri Dec 3 19:48:44 CET 2004

We are developing a package using S4 classes. The S4 classes
are wrappers to C++ classes. So S4 classes contain an integer
that is the memory address of one C++ object. If an user
calls the rm() function, the C++ object must be deleted. But our generic
rm() function apparently doesn't work. Here is the code:

# The class
setClass("component", representation(pointer="integer", "VIRTUAL"))

# The generic method
setGeneric("rm", function(..., list = object, pos = -1, envir = as.environment(pos), inherits = FALSE)  standardGeneric("rm"))

setMethod("rm", "component", function(list=object, pos, envir, inherits) {
	warning("object deleted")

We implemented generic methods for print(), show() and summary() succesfully.

Marcos Carrero

More information about the R-help mailing list