Re: [R] locked environment and inheritance

From: johan Faux <>
Date: Mon, 04 Jun 2007 14:13:40 -0700 (PDT)

Thanks for your reply.

Experimenting a little further, I was able to learn a bit more and find what is the real problem of mine what the real question is.

I could create my S4 extended class by adding these two lines in my namespace file importClassesFrom(Matrix,Matrix)

and then creating my new class in another R file

setClass("myMatClass", representation("dMatrix",myslot="numeric"))

which creates the new S4 class when my package is loaded.

The problem is that I would like to create the class inside a function of mine:

createMyS4Class() {


    setClass("myMatClass", representation("dMatrix",myslot="numeric")) }

so that, at some point (after my package is loaded ), I can do something like:

if (cond)


Now, I understand that at this point, my package environment is locked. So the question become: Is there any way that I can unlock my package environment, create my new S4 class and lock it back or something?

Please let me know if that makes sense ? I appreciate your comments.

-importing the foreign S4 class in my namespace file

johan Faux <> writes:

> Hi,
> I have a S3 package with namespace called "myS3Pkg". Inside my package
> I would like to create a S4 class which extends (adds 2 slots) another
> S4 class from some other package. The class should be created in
> "myPkg" environment (and not global environment).
> Using:
> setClass("myS4class", representation("otherS4class", mydata =
> "numeric"), where = topenv())

have you tried just omitting the where argument? Classes will get defined in the package environment and I think that's what you want.

+ seth

Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center


	[[alternative HTML version deleted]]

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 04 Jun 2007 - 21:19:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Jun 2007 - 17:31:26 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.