Re: [Rd] [R] function changes argument (PR#9216)

2006-09-11 Thread Prof Brian Ripley
On Mon, 11 Sep 2006, Peter Dalgaard wrote: > [EMAIL PROTECTED] writes: > > > I can tell you where the problem is and a workaround: > > > > f <- function(LL) for (ll in names(LL)) LL[[ll]]$txt<-"changed in f" > > > > works. The problem is that for() is directly exposing the elements of a > > l

Re: [Rd] [R] function changes argument (PR#9216)

2006-09-11 Thread Peter Dalgaard
[EMAIL PROTECTED] writes: > I can tell you where the problem is and a workaround: > > f <- function(LL) for (ll in names(LL)) LL[[ll]]$txt<-"changed in f" > > works. The problem is that for() is directly exposing the elements of a > list. > > Of course, a more idiomatic construction would be

Re: [Rd] [R] function changes argument (PR#9216)

2006-09-11 Thread ripley
I can tell you where the problem is and a workaround: f <- function(LL) for (ll in names(LL)) LL[[ll]]$txt<-"changed in f" works. The problem is that for() is directly exposing the elements of a list. Of course, a more idiomatic construction would be LL <- lapply(LL, function(x) x$txt <- "cha

Re: [Rd] [R] function changes argument (PR#9216)

2006-09-11 Thread Prof Brian Ripley
I can tell you where the problem is and a workaround: f <- function(LL) for (ll in names(LL)) LL[[ll]]$txt<-"changed in f" works. The problem is that for() is directly exposing the elements of a list. Of course, a more idiomatic construction would be LL <- lapply(LL, function(x) x$txt <- "cha

Re: [Rd] [R] function changes argument (PR#9216)

2006-09-11 Thread murdoch
(This report appeared in R-help. I've sent it separately to the bugs list to avoid a long string of cross-postings.) On 9/11/2006 4:49 AM, Moeltner, Andreas wrote: > Dear R-list, > > the following function f changes L. I thought, assignments within > functions are only local? That looks like a