[R] function input as variable name (deparse/quote/paste) ??

Hans Ekbrand hans at sociologi.cjb.net
Sun Mar 11 15:56:25 CET 2012


On Sat, Mar 10, 2012 at 04:01:21PM -0800, casperyc wrote:
> Sorry if I wasn't stating what I really wanted or it was a bit confusing.
> 
> Basically, there are MANY datasets to run suing the same function
> 
> I have written a function to analyze it and returns a LIST of useful out put
> in the variable 'res' (to the workspace).
> 
> I also created another script run.r such as
> 
> myname(dat1)
> myname(dat2)
> myname(dat3)
> myname(dat4)
> myname(dat5) 
> 
> For now, each time the output in the main workspace 'res' (the list) is over
> written.
> 
> I want it to have different suffix to differentiate them. So I can have a
> look later after the batch is run.

I see no advantage in having that information in variable names. Just

- add the name of the data set to the information that is included in
  the returned list.

- run your function with sapply() and the returned list of sapply will
  be a list of lists.

-- 
Hans Ekbrand (http://sociologi.cjb.net) <hans at sociologi.cjb.net>



More information about the R-help mailing list