Slightly related to this (I think Mr. Rydevik's code solved the question),
is a silly thing I wrote up one weekend. It started out as a clone of the unix "rm -i" command, and kept on going out of control :-)

I'm not claiming this is clean, or the best way to do this, but it does let you apply a wide variety of functions to your collection of 'items'

Carl

-------------
askrm<-function(items,fn="rm",ask=TRUE){
        killed<-NA
        thecall<-vector('list')
        j<-1
        
for (thenam in c(items)){
        if(ask==TRUE){
                prmpt<-paste("Do ",fn," on ",thenam,"? ")
                readline(prompt=prmpt)->theans
                }
                else theans="y"
        if(theans=="y"){
                
                #have to get to parent envir. to find the object of interest
                #as.name() gets rid of quotes...
                # paste() dumps all output into a single element of list
                # Note that,e.g., str() returns nothing, just cats to screen.
                eval(call(fn,as.name(thenam)),envir=parent.frame(1))->evout
                paste(evout,collapse=" ")->thecall[j]
                cat("the result is ", as.character(thecall[j]),'\n')
                killed[j]<-thenam
                j<-j+1
                }
        
        }
 #keeping track of what happened
 outs<-list(killed=killed, calls=thecall)
 return(invisible(outs))
 }

______________________________________________
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