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

2004-04-09 Thread Peter Dalgaard
Prof Brian Ripley <[EMAIL PROTECTED]> writes: > > This *should* be somewhere in the R Language Definition, although I'm > > not sure it is actually there. Or the blue book, although I suspect > > that S v.3 actually used positional matching (and jumped through > > hoops). > > It did. This is in

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

2004-04-09 Thread Prof Brian Ripley
On 7 Apr 2004, Peter Dalgaard wrote: > Robin Hankin <[EMAIL PROTECTED]> writes: > > > 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,

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

2004-04-07 Thread Duncan Murdoch
On 07 Apr 2004 13:51:52 +0200, Peter Dalgaard <[EMAIL PROTECTED]> wrote : >Duncan Murdoch <[EMAIL PROTECTED]> writes: >> Wouldn't a clearer syntax to follow be Pascal's? I.e. >> inc(x[3], 1) >> > >But that's not kosher in functional programming languages where you >expect function calls not to

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

2004-04-07 Thread Peter Dalgaard
Duncan Murdoch <[EMAIL PROTECTED]> writes: > On Tue, 6 Apr 2004 14:18:42 + (UTC), you wrote: > > >Robin Hankin soc.soton.ac.uk> writes: > >> R> a <- matrix(1:9,3,3) > >> But the following caught me off-guard: > >> R> a <- matrix(1:9,3,3) > >> R> a[a%%2==1] %+=% 1000*(1:5) > > > >How about th

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

2004-04-07 Thread Duncan Murdoch
On Tue, 6 Apr 2004 14:18:42 + (UTC), you wrote: >Robin Hankin soc.soton.ac.uk> writes: >> R> a <- matrix(1:9,3,3) >> But the following caught me off-guard: >> R> a <- matrix(1:9,3,3) >> R> a[a%%2==1] %+=% 1000*(1:5) > >How about this way: > >> a <- matrix(1:9,3,3) >> "plus<-" <- function(a,va

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

2004-04-07 Thread Peter Dalgaard
Robin Hankin <[EMAIL PROTECTED]> writes: > 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. > >

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

2004-04-07 Thread asemeria
Value in an internal variable of a command "function", have a look on R-help apropos "function". A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA),

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

2004-04-07 Thread Robin Hankin
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)

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

2004-04-06 Thread Gabor Grothendieck
Robin Hankin soc.soton.ac.uk> writes: > R> a <- matrix(1:9,3,3) > But the following caught me off-guard: > R> a <- matrix(1:9,3,3) > R> a[a%%2==1] %+=% 1000*(1:5) How about this way: > a <- matrix(1:9,3,3) > "plus<-" <- function(a,value) a+value > plus(a[a%%2==1]) <- 1000*(1:5) > a [,1] [,2

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

2004-04-06 Thread asemeria
Look at Syntax on R-help apropos operators precedence A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538

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

2004-04-06 Thread Duncan Murdoch
On Tue, 6 Apr 2004 13:36:32 +, Robin Hankin <[EMAIL PROTECTED]> wrote : > the following caught me off-guard: > > >R> a <- matrix(1:9,3,3) >R> a[a%%2==1] %+=% 1000*(1:5) >[1] 1001 2006 3015 4028 5045 >R> a > [,1] [,2] [,3] >[1,] 10014 1007 >[2,]2 10058 >[3,] 10036 1009 >R>

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

2004-04-06 Thread Peter Dalgaard
Robin Hankin <[EMAIL PROTECTED]> writes: > Some time ago, Peter Dalgaard made the wonderful suggestion to define > > "%+=%" <- function(a,b) {eval.parent(substitute(a <- a + b)) } ... > R> a <- matrix(1:9,3,3) > R> a[a%%2==1] %+=% 1000*(1:5) > [1] 1001 2006 3015 4028 5045 > R> a > [,1] [,2]

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

2004-04-06 Thread Robin Hankin
Some time ago, Peter Dalgaard made the wonderful suggestion to define "%+=%" <- function(a,b) {eval.parent(substitute(a <- a + b)) } Which I use (R-1.8.1) as follows: R> a <- matrix(1:9,3,3) R> a[a%%2==1] %+=% (1000*(1:5)) R> a [,1] [,2] [,3] [1,] 10014 4007 [2,]2 30058 [3,] 200