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

Hans Ekbrand hans at sociologi.cjb.net
Sat Mar 10 23:46:26 CET 2012


On Sat, Mar 10, 2012 at 01:29:16PM -0800, casperyc wrote:
> Hi all
> 
> Say I have a function:
> 
> myname=function(dat,x=5,y=6){
>     res<<-x+y-dat
> }
> 
> for various input such as
> 
> myname(dat1)
> myname(dat2)
> myname(dat3)
> myname(dat4)
> myname(dat5)
> 
> how should I modify the 'res' line, to have new informative variable name
> correspondingly, such as
> 
> dat1.res
> dat2.res
> dat3.res
> dat4.res
> dat5.res
> 
> stored in the workspace.

Why not keep the information of input values in a list, or vector?
What is gained by storing that info in the variable _name_ ? Your
function could return a list with both the result and the input value.

While you did say that this was part of something complex, I suspect
your post might be a case of "Being overly specific and not stating
your real goal."

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



More information about the R-help mailing list