Skip to content
Prev 40207 / 63421 Next

Reference Classes copy(shallow=FALSE) unexpected behavior.

Dear Hadley,

Thank you very much for your interest in the question proposed.
The Con class is a Reference Class. P and k are from class listCon.

I provide in the following lines a little more detail in order to be able
to reproduce the case.

#Class declaration
gCon <- setRefClass("Con", fields=list(from="ANY",weight="numeric"))
gListAMORE <- setRefClass("listAMORE", fields=list(.Data="list"))
gListCon <- setRefClass("listCon", contains="listAMORE")

# Let's create a few connections
con1 <- gCon$new(from=1, weight=1.1)
con2 <- gCon$new(from=2, weight=2.2)
con3 <- gCon$new(from=3, weight=3.3)

# And a list of connections
lcon <-gListCon$new()
lcon$.Data <- list(con1, con2, con3)

# At this point, lcon contains:
lcon$.Data
[[1]]
An object of class "Con"
<environment: 0x9a1534>

[[2]]
An object of class "Con"
<environment: 0xcd7ff0>

[[3]]
An object of class "Con"
<environment: 0xdca724>

# Let's copy lcon to k
k <- lcon$copy(shallow=FALSE)

# Now k is a new object but the cons are shared with lcon!
k$.Data
[[1]]
An object of class "Con"
<environment: 0x9a1534>

[[2]]
An object of class "Con"
<environment: 0xcd7ff0>

[[3]]
An object of class "Con"
<environment: 0xdca724>


Best regards

Manuel



El 11/05/11 14:00, "Hadley Wickham" <hadley at rice.edu> escribi?: