Skip to content
Prev 165029 / 398506 Next

passing arguments to subset from a function

I wrote a dirty hack last time I faced this problem, I'll be curious  
to see what is the proper way of dealing with the scoping and  
evaluation rules.

library(datasets)

myfunction<-function(table, extraction)  {
     table2<-subset(table,extraction)
return(table2)
}


condition1 <- quote(iris$Species=="setosa") # I'm not sure how to  
evaluate within the environment, perhaps you could use with(table,  
subset(table, extraction) ) in your function
condition2 <- bquote(.(condition1)  & iris$Sepal.Width < 3.5) # say,  
if you want to concatenate several conditions together

myfunction(iris, extraction= eval(condition1))
myfunction(iris, extraction= eval(condition2))


Best wishes,

baptiste
On 17 Dec 2008, at 19:07, GOUACHE David wrote:

            
_____________________________

Baptiste Augui?

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag