On Sun, Mar 11, 2012 at 10:29 AM, casperyc <caspe...@hotmail.co.uk> 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
You *can* do it with myname=function(dat,x=5,y=6){ name<-paste(deparse(substitute(dat)),"res",sep=".") assign(name, x+y-dat, parent.frame(), inherits=TRUE) } but I would be very surprised if this is actually the best way to do whatever complex thing you are really doing. It's very unusual for assignments into the global workspace to be a useful R programming technique. -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland ______________________________________________ R-help@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.