Thanks Gabor/Duncan,

I might give that proto package a try. The R.oo package is more intuitive
for someone coming from a traditional OO background, but compared to proto,
it looks like it requires a lot more typing to create the same amount of
functionality. I've used R.oo for a number of months now and it works
great.  The other option is to just use get() and assign(), like I
suggested in my original post, which seems to be the simplest, but more
typing than proto.

Thanks for the info! Have a good weekend...

ben

On Wed, Feb 15, 2012 at 11:09 PM, Gabor Grothendieck <
ggrothendi...@gmail.com> wrote:

> On Wed, Feb 15, 2012 at 11:58 PM, Ben quant <ccqu...@gmail.com> wrote:
> > Thank you Duncan. Interesting. I find it strange that you can't get a
> list
> > of the environments. But I'll deal with it...
> >
> > Anyway, I'm about to start a new R dev project for my company. I'm
> thinking
> > about architecture, organization, and gotchas. I went through much of the
> > documentation you sent me. Thanks!. I came up with what I think is the
> best
> > way to implement environments (which I am using like I would use a class
> in
> > a traditional OO language) that can be reused in various programs.
> >
> > I'm thinking of creating different scripts like this:
> > #this is saved as script name EnvTest.R
> > myEnvir = new.env()
> > var1 = 2 + 2
> > assign("myx",var1,envir=myEnvir)
> >
> > Then I will write programs like this that will use the environments and
> the
> > objects/functions they contain:
> > source("EnvTest.r")
> > prgmVar1 = get("myVar1",pos=myEnvir)
> > ## do stuff with env objects
> > print(prgmVar1)
> >
> > Do you think this is the best way to use environments to avoid naming
> > conflicts, take advantage of separation of data, organize scripting
> > logically, etc. (the benefits of traditional OO classes)? Eventually,
> I'll
> > use this on a Linux machine in the cloud using.:
> > https://github.com/armstrtw/rzmq
> > https://github.com/armstrtw/AWS.tools
> > https://github.com/armstrtw/deathstar
> > http://code.google.com/p/segue/
>
>
> Reference classes, the oo.R package and the proto package provide OO
> implementations based on environments.
>
> Being particular familiar with the proto package
> (http://r-proto.googlecode.com), I will discuss it.  The graph.proto
> function in that package will draw a graphViz graph of your proto
> objects (environments).  Using p and x in place of myEnv and myx your
> example is as follows.
>
> library(proto)
> p <- proto(x = 2+2)
> p$x  # 4
>
> # add a method, incr
> p$incr <- function(.) .$x <- .$x + 1
> p$incr() # increment x
> p$x # 5
>
> # create a child
> # it overrides x; inherits incr from p
> ch <- p$proto(x = 100)
> ch$incr()
> ch$x # 101
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to