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

From: <murdoch_at_stats.uwo.ca>
Date: Mon 11 Sep 2006 - 10:56:18 GMT


(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 bug, still present in R-patched and R-devel. (I haven't got the latest pre-release built yet today, but I expect it's there, too.) Thanks for the report.

I'll send a copy of this to the bugs list, but I won't be able to attempt to fix it.

Duncan Murdoch

>
>
> f<-function(LL)
> { for (ll in LL)
> { ll$txt<-"changed in f"
> }
> }
>
> l<-list(txt="original value")
> L<-list(l)
> L[[1]]$txt
> f(L)
> L[[1]]$txt
>
>
> gives (using R 2.3.1):
>
> ...

>> L[[1]]$txt

> [1] "original value"
>> f(L)
>> L[[1]]$txt

> [1] "changed in f"
>
> Thanks in advance
>
> Andreas
>
> ______________________________________________

> R-help@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
> and provide commented, minimal, self-contained, reproducible code.


R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon Sep 11 21:00:35 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 11 Sep 2006 - 13:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.