[R] "<<-" assignment no long work in class methods

Gang Liang liang at ics.uci.edu
Thu Nov 11 05:20:01 CET 2004


Hi-

I used to use "<<-" to do assignment inside a class method, and
just found that now it is broken in R 2.0. For example, the
following code

-----------------------------------------------------------------------
setClass( "myclass", representation(x="numeric") )
setGeneric("incrXByOne", function(obj) standardGeneric("incrXByOne"))
setMethod( "incrXByOne", "myclass", function(obj) obj at x <<- obj at x + 1 )

incrXByOne( new("myclass") )
-----------------------------------------------------------------------

will give an error message like:

   Error in incrXByOne(new("myclass")) : Object "obj" not found
   ## R failed to trace the object back to the GlobalEnv...

It used to work under R1.7 - 1.9. I don't know whether this is a
bug or a new feature...

Anyone can recommend a workaround?

Thanks, Gang

-----------------------------
debian unstable, kernel 2.6.8

> version

platform i386-pc-linux-gnu
arch     i386
os       linux-gnu
system   i386, linux-gnu
status
major    2
minor    0.0
year     2004
month    10
day      04
language R




More information about the R-help mailing list