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]]
On 22/06/2014, 6:00 AM, Ragia Ibrahim 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 functionsThe reason is that <<- doesn't do what you think it does. It is useful in a very narrow context, but not the way you're using it. For what you're doing, you don't need it. Here's a better way to get what you want: Change function 1 to look like this: list1 <- function2(list1) list1 <- function3(list1) list1 <- function4(list1) and change functions 2, 3, 4 to not use <<-, but to return the modified list, e.g. function2 <- function(list1) { list1 <- ... list1 } Duncan Murdoch
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.