microbiome / mia

Microbiome analysis
https://microbiome.github.io/mia/
Artistic License 2.0
47 stars 28 forks source link

Fix estimateDiversity input check #519

Closed TuomasBorman closed 5 months ago

TuomasBorman commented 5 months ago

Related to this PR https://github.com/microbiome/mia/pull/514

I noticed that match.args is little bit problematic in estimateDiversity functions' input check. It subsets indices that are supported without giving any notification if user inputted unsupported indices along with supported ones. Also, name parameter gets index as default value and it is not updated after match.args call which leads to missmatch and uninformative error.

library(mia)

data(GlobalPatterns)
tse <- GlobalPatterns

index <- c("shannon", "test")
# Uninformative error
res <- estimateDiversity(tse, index = index)

# "shannon" passes through in match.args call. Now this works
index <- c("shannon", "test")
name <- c("shannon")
res <- estimateDiversity(tse, index = index, name = name)

-->

Fix input check for index parameter. Instead of using match.args, check that all the indices are supported ones.

supported_index <- c("shannon", "index2")
if( !all( index %in% supported_index ) ){
    stop("'index' contains unsupported indices.", call. = FALSE)
}