[Rd] Plans for tighter integration of reference classes in R.

Vitalie S. spinuvit.list at gmail.com
Sat Oct 23 14:43:56 CEST 2010


Hello Everyone!  Here are a couple of thought/questions on refClasses
integration in R core functionality.

First, coexistence with S4:

> X <- setRefClass("classX", fields = c("a", "b"),
+                  representation = list(c = "character"))
> x <- X$new()
> x at c <- "sss"
> x
An object of class "classX"
<environment: 059bf6a4>
Slot "c":
[1] "sss"

The above is cool, S4 and refClasses apparently live happily together.
But, 

> x$.self
An object of class "classX"
<environment: 059bf6a4>
Slot "c":
character(0)

This is not a surprise, taking into account the copping paradigm of R.
Are there any plans to tighten S4<>refClasses integration? Or it's just not a
good idea to mix them as in the above example?


Second, R core integration (this bothers me much more):

> X$methods(m = function(t) a*t)
> environment(x$m)
<environment: 059bf6a4>

environment(..) does not return the refObject but the basic type. I assume that
it is the same with other core functionality. Usage of refObjects as parent.env
is also probably precluded in the similar way (don't have a patched R, so can
not test yet).

Would it be possible, some day, to use refObjects as parent.env or function's
environment  without "loosing the class"?

Parenthetically, the attributes of an object (including S3 classes) are not lost:

> env <- structure(new.env(), a1 = "fdsf", class = "old_class")
> tf <- function(x)x
> environment(tf) <- env
> environment(tf)
<environment: 056570a0>
attr(,"a1")
[1] "fdsf"
attr(,"class")
[1] "old_class"
> class(environment(tf))
[1] "old_class"
> 

Thanks,
Vitalie.



More information about the R-devel mailing list