MoBiodiv / mobr

Tools for analyzing changes in diversity across scales
Other
23 stars 18 forks source link

control for fail when effort = NA and index = 'S_n' #257

Closed AlbanSagouis closed 3 years ago

AlbanSagouis commented 3 years ago

In calc_div, instead of deleting the default parameter for effort, a similar check as in calc_comm_div could be made. With this change, the errors are more informative: Before:

> data(inv_comm)
> calc_comm_div(inv_comm, 'S_n')
Error in if (any(effort > n)) { : missing value where TRUE/FALSE needed
> calc_div(inv_comm[1,], 'S_n')
Error in if (any(effort > n)) { : missing value where TRUE/FALSE needed

After:

> calc_comm_div(inv_comm, 'S_n')
Error in calc_comm_div(inv_comm, "S_n") : 
  effort value is needed to compute S_n
> calc_div(inv_comm[1, ], 'S_n')
Error in rarefaction(x, method = "IBR", effort = effort, ...) : 
  argument "effort" is missing, with no default
dmcglinn commented 3 years ago

Thanks @AlbanSagouis ! This seems totally reasonable. In the master branch of the repo we use the function get_mob_stats to feed the function calc_biodiv effort levels even when they are not supplied by the user: https://github.com/MoBiodiv/mobr/blob/master/R/mobr_boxplots.R#L615-L626

I think we'll continue that kind of implementation, but your patch is helpful because some users will just want to use calc_div and calc_comm_div directly. Tagging Issue #256