Issue with aggregate function in getExpansion_2 via application to canary age comp expansion #104
Labels
priority: low
The lowest level priority, i.e., not urgent.
status: in progress
Currently working on this issue
topic: code
Related to R code within this package
type: refactor
Changes to the codebase or documentation that do NOT alter the values returned, e.g., styling.
Describe the bug
Im encountering an issue with the getExpansion_2 function when I try to expand age comps for canary rockfish across the entire coast. The specific line where this issue occurs in when trying to figure out the trips that dont have catch values associated with them, line 162-163. When I expand based on state, I dont have this issue.
The reason why this is occurring is that when I try to expand across the coast, all trips with no catch also have NA for Sum_Sampled_Lbs. Thus aggregate(Sum_Sampled_Lbs ~...) does not work. When I expand across each state, there are more trips with no catch, and most of these have values for Sum_Sampled_Lbs.
This appears to be a very case-specific issue. In this case, when expanding across the coast my catches run from 1981 on but i have age comps for 1980. It just so happens to be that the only records with Sum_Sampled_Lbs==NA occur in 1980. When expanding by state, other years are added because not every state starts with catches in 1981, and thus there are some postivie Sum_Sampled_Lbs.
To Reproduce
I cant really reproduce because I would have to share catches. However, a minimally reproducible example is below showing that the formula formulation of aggregate doesn't work when the y ~ value is all NA:
Additional context
I see two solutions to this. First use the less elegant formulation for aggregate, like I do above. Within lines 162-163 this would look like
Second, use a dplyr group_by formulation.
I tried these two options and both ran, overcoming my original issue. I ran though length comps output for one column and the results were the same across all three approaches (the original, and then my two choices).
The text was updated successfully, but these errors were encountered: