[R] %+=% and eval.parent()

Robin Hankin rksh at soc.soton.ac.uk
Wed Apr 7 11:09:51 CEST 2004


Hi again everybody.

Yesterday I had a problem with c-style "+=" functions.  One suggestion
was to define

R> "plus<-" <- function(x,value){x+value}

Then

R> a <- matrix(1:9,3,3)
R> plus(a[a%%2==1]) <- 1000

works as desired.


QUESTION: why does this behave differently:


R> "plus<-" <- function(x,y){x+y}
R> a <- matrix(1:9,3,3)

R> plus(a[a%%2==1]) <- 1000
Error in "plus<-"(`*tmp*`, value = 1000) :
	unused argument(s) (value ...)
R>

The only change seems to be changing the second argument from "value"
to "y".  Why does this affect anything?  Where do I look for
documentation on things like "plus<-"  ?

-- 
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam precaution)




More information about the R-help mailing list