r - Passing argument to subset() and unique() -


i using phyloseq package.

test <- function( ...){  bar <- unique(sampledata[,'ph'])  foo <- subset_samples(phyloseqobject, ph == as.numeric(bar[1]@.data)) print(foo)  }  test(ph) 

i want pass ph argument test() unique() won't accept valid. can pass 'ph' test() subset_samples() won't accept valid. have tried coercing argument several different types no luck.

sorce subset_samples:

subset_samples <- function(physeq, ...){     if( is.null(sample_data(physeq)) ){          cat("nothing subset. no sample_data in physeq.\n")         return(physeq)     } else {         olddf <- as(sample_data(physeq), "data.frame")         newdf <- subset(olddf, ...)         if( class(physeq) == "sample_data" ){             return(sample_data(newdf))         } else {             sample_data(physeq) <- sample_data(newdf)             return(physeq)         }     } } 

try instead:

test=function(x,...){    bar=unique(mtcars[,x])    foo=subset(mtcars,mtcars[,x]==bar[1])    return(foo) } 

Comments