fishR-Core-Team / FSA

FSA (Fisheries Stock Assessment) package provides R functions to conduct typical introductory fisheries analyses.
https://fishr-core-team.github.io/FSA/
GNU General Public License v2.0
65 stars 20 forks source link

wsVal() fails ungracefully in some situations #89

Closed droglenc closed 1 year ago

droglenc commented 2 years ago

The wsVal() function only works with some species but also defaults to using metric units and 75th percentile equations. However, it sends the same error message if any one of those three things does not exist in WSlit which is not particularly useful as the user does not know if the problem is that species does not exist or, for example, the species exists but there is no equation for the 75th percentiles. An example is for Bighead Carp, which exist in WSlit but only as a 50th percentile equation.

wsVal("Bighead Carp")
 Error: A Ws equation may not exist given your choices of species, units, and ref.
Please look carefully inside the data(WSlit) data frame.
wsVal("Bighead Carp",ref=50)
       species  units   type ref measure method min.TL      int   slope              source
7 Bighead Carp metric linear  50      TL    RLP    160 -4.65006 2.88934 Lamer et al. (2019)

The error would be more informative if we checked first to see if the species exists, send a message if it does not, then move on to check the units, send a message if the equation does not exist for those units, and then check the reference percentile, and send a message if that does not exist.

droglenc commented 1 year ago

In v0.9.4 of FSA, the error described above will look like this ...

wsVal("Bighead Carp")
       species  units   type ref measure method min.len max.len      int
7 Bighead Carp metric linear  50      TL    RLP     160      NA -4.65006
    slope quad              source comment
7 2.88934   NA Lamer et al. (2019)    none
Error: There is no Ws equation with ref of 75 for Bighead Carp.
Please see relevant portion of `WSlit` above.

In addition, this is what a bet units= error will look like ...

wsVal("Ruffe",units="English")
    species  units      type ref measure method min.len max.len     int
141   Ruffe metric quadratic  50      TL    EmP      55     205 -3.3524
142   Ruffe metric quadratic  75      TL    EmP      55     205 -2.5800
     slope   quad                   source comment
141 1.3969 0.4054 Ogle and Winfield (2009)    none
142 0.6210 0.6073 Ogle and Winfield (2009)    none
Error: There is no Ws equation in English units for Ruffe.
Please see relevant portion of `WSlit` above.

And, a bad species= error ...

wsVal("Derek")
Error: There is no Ws equation in 'WSlit' for Derek.
Type 'wsVal()' to see a list of available species.