Skip to content

sequencing environments

6 messages · Ben quant, Gabor Grothendieck, Duncan Murdoch

#
On 12-02-14 12:34 AM, Ben quant wrote:
Environments are objects and most of them are maintained in the same 
places as other objects (including some obscure places, such as in 
structures maintained only in external package code), so it's not easy 
to generate a complete list.
I would suggest reading the technical documentation:  the R Language 
manual, the R Internals manual, and some of the papers on the "Technical 
papers" page.

Duncan Murdoch
1 day later
#
On Wed, Feb 15, 2012 at 11:58 PM, Ben quant <ccquant at gmail.com> wrote:
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
#
On 12-02-15 11:58 PM, Ben quant wrote:
I'd advise thinking really carefully about this, because I think it 
indicates you've got a mental model of R internals that isn't a good 
match to what's really going on.  The kinds of things you might think about:

Would you find it just as strange that you can't easily get a list of 
all character vectors?  Environments aren't really more special than 
other objects.

If you think it's strange that you can't get a list of all character 
vectors, then consider that many of them aren't bound to names, so 
they'll have a C-level pointer to identify them, but they'll be hard to 
get to from within R.

The memory manager has a list of all objects and it goes through this 
list during garbage collection, but that's not something that user-level 
code should be able to do (except possibly debugging code).
I would recommend that you avoid inventing another object system.  R 
currently has too many of those, and it means that lots of good code is 
unreadable by people who use a different one than you chose.

Gabor gave a list of existing systems based on environments; besides 
those you should consider the S4 system without reference classes (from 
the methods package).

I don't know any of them well enough to tell you how to choose, but I 
think if you put together prototypes of your project you'll run into 
problems with any of them, and a big part of your choice should be to 
see how easy it is to resolve those problems:  Do you get good help from 
the documentation?  Do you get good help on the mailing lists or 
Stackoverflow?


Duncan Murdoch
1 day later