[R] local and global variables

Bert Gunter gunter.berton at gene.com
Sun Jun 22 08:12:50 CEST 2014


What you want here, of course, is pass by reference. It can be done in
R (via environments), but in general, it violates the functional
programming paradigm that mostly underlies R. So you should heed the
advice given to you by Duncan and Jeff.

Cheers,
Bert



Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Sat, Jun 21, 2014 at 9:33 PM, Jeff Newmiller
<jdnewmil at dcn.davis.ca.us> wrote:
> You are not following the Posting Guide. This is a plain text mailing list (HTML does not necessarily show us what you see). Also, you should be providing a reproducible example that we can run to understand what you are actually dealing with.
>
> The only general advice I can give you at this point is that you should avoid using <<- at all. Instead, return results or lists of results from the functions and assign them to global variables where you call the functions.
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
>                                       Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On June 21, 2014 9:00:53 PM PDT, Ragia Ibrahim <ragia11 at hotmail.com> wrote:
>>Dear group
>>I have some thing like the following code...
>>##start
>>my_list (global object)
>>
>>function 1
>>{
>>list1<-mylist
>>
>>function2(list1)
>>function3(list1)
>>function4(list1)
>>}
>>
>>function2(list1)
>>{
>>assign values via <<- to the object items
>>}
>>
>>function3(list1)
>>{
>>assign values via <<- to the object items
>>}
>># end
>>
>>
>>why after finishing each function the object variable is NULL..how can
>>i keep its values across functions.
>>
>>Regardes
>>RAE
>>
>>       [[alternative HTML version deleted]]
>>
>>______________________________________________
>>R-help at r-project.org 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-help at r-project.org 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.



More information about the R-help mailing list