[Rd] Ghost RefClasses

From: Tyler Pirtle <rtp_at_google.com>
Date: Wed, 16 May 2012 09:27:11 -0700


Hi there, this seems weird to me. Perhaps someone can explain whats going on?

I'm creating a RefClass, then unloading the methods package, then re-loading it, declaring
a different refclass with the same name, loading that one, but i'm getting instances of the
previously defined class.

$ R

R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) ....

> # Make a function that returns a RefClass.
> boot <- function() {

+   library(methods)
+   setRefClass("someclass", fields = list(a = "numeric"),
+                   methods = list(
+                     addSome = function(){
+                       a <<- a+1
+                       a
+                     }))
+ }

> j <- boot()
> s <- j$new(a=1)
> s$addSome()
> # Unload (detach) methods.
> detach("package:methods", character.only=TRUE, force=TRUE, unload=TRUE)
unloading 'methods' package ...
> search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics"
[4] "package:grDevices" "package:utils"     "package:datasets"
[7] "Autoloads"         "package:base"

> # Define a new class, load methods.
> boot2 <- function() {
+   library(methods)
+   setRefClass("someclass", fields = list(a = "numeric"),
+                   methods = list(
+                     addSome = function(){
+                       a <<- a+3
+                       a
+                     }))
+ }

> j <- boot2()
> s <- j$new(a=1)
> s$addSome()

[1] 2

I'd expect the last call to addSome to be 4, not 2.

Thanks,

Tyler

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 16 May 2012 - 16:30:10 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Wed 16 May 2012 - 21:41:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive