Skip to content

Commit

Permalink
fix(getExpansion_2): close #104 uses dplyr::count
Browse files Browse the repository at this point in the history
remove stats::aggregate b/c the formula interface was not working in some
instances and changes to using dplyr::group_by and then count()
  • Loading branch information
kellijohnson-NOAA committed Apr 4, 2023
1 parent 689f7db commit fa307b3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions R/getExpansion_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,18 @@ getExpansion_2 <- function(Pdata, Catch,
)

# Find which trips don't have catch values associated with them
if (sum(is.na(tows[, "catch"])) != 0){
NoCatch <- stats::aggregate(Sum_Sampled_Lbs ~ fishyr + stratification,
data = tows[is.na(tows[, "catch"]), ], length)
colnames(NoCatch)[3] <- "N"
if (length(NoCatch) > 0 & verbose) {
message("No Catch was found for these rows in Pdata, where\n",
"N is the number of rows with missing Catch info:")
trips_without_catch <- dplyr::filter(tows, is.na(catch))
if (NROW(trips_without_catch) > 0) {
NoCatch <- dplyr::group_by(
.data = trips_without_catch,
fishyr, stratification
) %>%
dplyr::count(Sum_Sampled_Lbs)
if (length(NoCatch) > 0 && verbose) {
message(
"No Catch was found for these rows in Pdata, where\n",
"n is the number of rows with missing Catch info:"
)
print(NoCatch)
} # End if
}
Expand Down

0 comments on commit fa307b3

Please sign in to comment.