Greetings All!

After much trial and error, and an exhaustive search of the archives, I'm
writing to solicit help with a problem.

I want to dynamically modify variable names and values as function arguments
inside a loop.

I have a canned function from a package that takes ellipsis (...) arguments
of the form varb=vval where varb is a name and vval is either numeric or
character. I want to create a dynamic version of this function for batch
processing that allows the varb and vval to be variable. For instance, in
this toy example:

a.func<-function(...){
  does.something(...)
 }

#I need to pass varb as a character
my.func<-function(dat,varb){
  dat.col<-dat[,varb]
  vval<-unique(dat.col)
  for(i in 1:length(vval){
  outpm<-a.func(eval(args))
  }
 return(outpm)
}

#Intuitively, the following should work (but does not):

my.func<-function(dat,varb){
  dat.col<-dat[,varb]
  vval<-unique(dat.col)
  for(i in 1:length(vval){

args<-attr(parse(text=paste(varb,"=","\"",vval[i],"\"",sep="")),"wholeSrcref")
  outpm<-a.func(eval(args))
  }
return(outpm)
}

Any help is much appreciated, and I thank you for your time.

Here is a link to a similar problem that another useR recently posted:
https://stat.ethz.ch/pipermail/r-help/2011-January/264719.html

Best,
Christopher Marcum
Doctoral Candidate
Sociology Department
University of California, Irvine

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to