Open mhoban opened 1 year ago
It's a persistent issue that is unfortunately not resolved. Both subset_samples() and subset_taxa() (and maybe other functions as well) have a scoping issue and do not recognise function variables.
The workaround is to either use the <<-
operator or assign the variables before calling the function. e.g.:
data(GlobalPatterns)
sample_type = "Ocean"
subset_function <- function(physeq_obj = GlobalPatterns, sample_type ){
subset_samples(GlobalPatterns, SampleType==sample_type)
}
subset_function(GlobalPatterns, sample_type = "Ocean")
The function
subset_taxa
(and probably other similar functions that use ellipses to pass subset expressions) can only handle expressions passed where all referenced objects are in the global scope, so (for example) trying to subset aphyloseq
object inside of a function where you've defined the criteria won't work. See this simple example:I encountered this because I was trying to use the
purrr
map functions to take differing subsets of a ps object and do stuff with that, like this:I can set
.x
to something global using the<<-
operator, but that feels very kludgy and may affect other things down the line