sizespectrum / mizer

Multi-species size-based ecological modelling in R
https://sizespectrum.org/mizer
38 stars 43 forks source link

Give useful error if `valid_species_arg()` is called only with invalid names #251

Closed gustavdelius closed 2 years ago

gustavdelius commented 2 years ago

Currently a warning is issued if some of the species names are invalid and these are removed. If all species names are invalid, then a vector of length 0 is returned. This may trip up some of the functions using valid_species_arg(). It would be better if an error was thrown.

gustavdelius commented 2 years ago

Actually, often there is no problem with returning a vector of length 0. It is only in the plot functions that this is a problem because it leads to an empty plot and if that is then used in the plotly version of the function it throws the cryptic error message: "Error in order(data[["x"]]) : argument 1 is not a vector".

So I propose an extra boolean argument error_on_empty defaulting to FALSE, which can then be set to TRUE when called in functions that can't handle the empty list.