To test two environments for object equality (Lisp EQ), I can use 'identity':
> e1 <- environment(local(function()x))
> e2 <- environment(local(function()x))
> identical(e1,e2) # compares object identity
[1] FALSE
> identical(as.list(e1),as.list(e2)) # compares values as name->value mapping
[1] TRUE # (is there a better way to do this?)
What is the corresponding function for testing whether two S4 objects
are the same object? It appears that 'identity' for S4 objects
compares the *value*, not the *object identity*:
> setClass("simple",representation(a="logical"))
[1] "simple"
> s1 <- new("simple"); s2 <- new("simple")
> identical(s1,s1)
[1] TRUE # not surprising
> identical(s1,s2)
[1] TRUE # ? not comparing object identity
> s...@a <- TRUE
> s...@a <- TRUE
> identical(s1,s2)
[1] TRUE
> s...@a <- TRUE
> s...@a <- FALSE
> identical(s1,s2)
[1] FALSE
Thanks,
-s
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.