pfmc-assessments / PacFIN.Utilities

R code to manipulate data from the PacFIN database for assessments
http://pfmc-assessments.github.io/PacFIN.Utilities
Other
7 stars 1 forks source link

fix writeComps() bug with CAAL columns #93

Closed iantaylor-NOAA closed 1 year ago

iantaylor-NOAA commented 1 year ago

For reasons that I don't understand, after updating PacFIN.Utilities today, I started getting Error in x[[jj]][iseq] <- vjj : replacement has length zero when running writeComps() for CAAL data. I tracked it down to a missing "b" column which is corrected by this Pull Request.

I don't know what caused the bug or what's going on in the area that I fixed, I was just following the pattern I see in the non-CAAL code immediately above. In general we never use vectors of both females and males for CAAL data, so an alternative solution would be to skip that option when writing CAAL data.

To replicate the error, get the petrale bds data off the NWFSC network (which @chantelwetzel-noaa created) and source this file https://github.com/pfmc-assessments/petrale/blob/main/R/process_pacfin_bds.R up through writing the CAAL data on line 430.

chantelwetzel-noaa commented 1 year ago

@iantaylor-NOAA Thank you for finding and correcting this issue. The writeComps loops across all sex combinations (females and males, females alone, males alone, and unsexed alone) regardless of the data being processed (lengths, marginal ages, or CAAL). I can see how this would have caused issues even though the female and males CAAL are not output. I am going to test the fix for a different species and will merge the pull request once this is completed,

kellijohnson-NOAA commented 1 year ago

@iantaylor-NOAA sorry for the 🐛 and thanks for such detailed information on how you got some data and worked through a script to find what was going on. Super helpful for tracking things later. I also really appreciate you @chantelwetzel-noaa for checking the fix and merging it in. Thanks for all of your help!