[R] passing arguments to subset from a function

Vitalie S. vitosmail at rambler.ru
Wed Dec 17 21:27:38 CET 2008


On Wed, 17 Dec 2008 20:07:08 +0100, GOUACHE David <D.GOUACHE at arvalisinstitutduvegetal.fr> wrote:
> argument which I will pass on to subset() somewhere inside my function.  


I would use the example of .() function from plyr package in this case:

.<-function (...){
     structure(as.list(match.call()[-1]), class = "quoted")
}

myfunction<-function(table, extraction)  {
     table2<-subset(table, eval(extraction[[1]]))
     return(table2)
 }
myfunction(iris, extraction = .(Species=="setosa"))

You can pass as many arguments in .() as you wish and index correspondingly in myfunction afterwards.

HTH.



More information about the R-help mailing list