Skip to content
Back to formatted view

Raw Message

Message-ID: <op.umbpscridacko8@tir-070312.staff.few.eur.nl>
Date: 2008-12-17T20:27:38Z
From: Vitalie S.
Subject: passing arguments to subset from a function
In-Reply-To: <1DF7DB4AB44EFB41A60A889186D43359252DC4@srv-laminiere.arvalis-fr.com>

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.