1

I am using the phyloseq package.

test <- function( ...){

bar <- unique(sampleData[,'pH'])

foo <- subset_samples(phyloseqObject, pH == as.numeric(bar[1]@.Data))
print(foo)

}

test(pH)

I want to pass pH as an argument to test() but unique() won't accept it as valid. I can pass 'pH' to test() but subset_samples() won't accept that as valid. I have tried coercing the argument to several different types with no luck.

SORCE for 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)
        }
    }
}
www
  • 38,575
  • 12
  • 48
  • 84
Alexander
  • 480
  • 2
  • 5
  • 21

2 Answers2

1

Try this instead:

test=function(x,...){
   bar=unique(mtcars[,x])
   foo=subset(mtcars,mtcars[,x]==bar[1])
   return(foo)
}
desc
  • 1,190
  • 1
  • 12
  • 26
0

Building on what @desc said I managed to solve it like this:

test <- function(...){

    bar <- unique(sampleData[,...])

    foo <- subset_samples(phyloseqObject, eval(parse(bar@names)) == as.numeric(bar[1]))
    print(foo)

}

test('pH')
Alexander
  • 480
  • 2
  • 5
  • 21