Skip to content
Back to formatted view

Raw Message

Message-ID: <CAAmySGP=g6NWsnjf3uaiSXQ_=ed+c_cdipUbHSFNwoTKQorDcQ@mail.gmail.com>
Date: 2011-11-07T14:17:26Z
From: R. Michael Weylandt
Subject: function that load variables
In-Reply-To: <1320673204.93299.YahooMailNeo@web120104.mail.ne1.yahoo.com>

Perhaps you mean to use

load(...., envir = .GlobalEnv)

Currently you load up the variables in the function environment but
then they are thrown away when the function ends.

Michael

On Mon, Nov 7, 2011 at 8:40 AM, Alaios <alaios at yahoo.com> wrote:
> Dear all,
> I have saved few variable names into local files,
> I wanted to make a function that load this files and "generates" the variable names into my working environment. I have tried to do that as a function but my problem is
>
> that this function does not return the variable names
>
>
> load_data<-function(path,Reload=FALSE){
>
> ??? if (Reload==TRUE){
>
> ??? ? print("Loading results")
>
> ??? ? # FirstSet
> ??? ? load(file=paste(path,'first',sep=""))
> ??? ? first<-Set
>
> ??? ? # SecondSet
> ??? ? load(file=paste(path,'second',sep=""))
> ??? ? second<-Set
>
> ..................(part omittted here)
>
> ??? ? save( first, second,....(part omitted here)...,???? file=paste(path,'Results',sep=""))
> ??? }
>
> ??? return (load(file=paste(path,'Results',sep="")))
>
> }
>
> so my idea was the following:
> I call the function and it retuns the values first,second,... loaded into the current working space.
> If I want to refresh them, something has changed to the firstDataSet I set the function's variable Reload=True and thus all the data are refreshed.
> The problem is not that the return statement I ahve at the end of the function does not return the loaded variable to the working environment but only the status of the load command.
>
> Do you know how I can change that so my function returns also Loaded Variable names to the environment?
>
> Alex
> ? ? ? ?[[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.
>
>