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]]