[R] "<<-" assignment no long work in class methods
Witold Eryk Wolski
wolski at molgen.mpg.de
Thu Nov 11 08:30:25 CET 2004
Gang Liang wrote:
>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 )
>
>
>
Hi,
What (my guess) you want to define is:
setMethod( "incrXByOne", "myclass", function(obj) {obj at x <- obj at x + 1;obj})
You do not need "<<-" to assign to a function argument? Its in my view
even erroneous.
This S code gives an error too.
test <- function(x)
{
x$bla<<-x$bla + 1
}
test(1)
Error in test(1) : Object "x" not found
/E
>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
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>
--
Dipl. bio-chem. Witold Eryk Wolski
MPI-Moleculare Genetic
Ihnestrasse 63-73 14195 Berlin
tel: 0049-30-83875219 __("< _
http://www.molgen.mpg.de/~wolski \__/ 'v'
http://r4proteomics.sourceforge.net || / \
mail: witek96 at users.sourceforge.net ^^ m m
wolski at molgen.mpg.de
More information about the R-help
mailing list