Skip to content

Commit

Permalink
Merge pull request #7 from NOAA-EDAB/func_bugfix
Browse files Browse the repository at this point in the history
bug fix in get_latest_metrics
  • Loading branch information
andybeet authored Feb 24, 2022
2 parents d2c772f + a0924b6 commit 1e09fd2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: stocksmart
Title: Provides access to NOAAs stock SMART data
Version: 0.3.3
Version: 0.3.4
Authors@R:
person(given = "Andy",family = "Beet", role = c("aut", "cre"),
email = "[email protected]",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# stocksmart 0.3.4

## Minor Bugs

* Fixed bug in filtering of data in `get_latest_metrics` function

# stocksmart 0.3.3

* Data pull Feb 23, 2022
Expand Down
11 changes: 10 additions & 1 deletion R/get_latest_metrics.r
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

get_latest_metrics <- function(itis=NULL, metrics = c("Catch","Abundance")) {


#error check for metric names
if (!all(metrics %in% c("Catch","Abundance","Fmort","Recruitment"))) {
stop("Please check the spelling of metrics used. Only \"Catch\",\"Abundance\",\"Fmort\",\"Recruitment\" are permitted")
}


# Filter Full Updates or Benchmark assessments
allData <- stocksmart::stockAssessmentData %>%
dplyr::filter(.data$UpdateType %in% c("Benchmark","Full Update"))
Expand Down Expand Up @@ -49,10 +56,12 @@ get_latest_metrics <- function(itis=NULL, metrics = c("Catch","Abundance")) {
.data$AssessmentYear) %>%
dplyr::summarise(sumMetric = dplyr::n(),.groups="drop") %>%
dplyr::filter(.data$sumMetric == length(metrics)) %>%
dplyr::group_by(.data$StockName,.data$CommonName,.data$StockArea,.data$ITIS) %>%
dplyr::filter(.data$AssessmentYear == max(.data$AssessmentYear)) %>%
dplyr::left_join(.,allStats,by = c("StockName","ITIS","CommonName","StockArea","AssessmentYear")) %>%
dplyr::select(-.data$sumMetric) %>%
dplyr::filter(.data$Metric %in% metrics)
dplyr::filter(.data$Metric %in% metrics) %>%
dplyr::ungroup()

# select the full time series for the most recent assessments that have all 4 metrics reported
data <- stats %>%
Expand Down

0 comments on commit 1e09fd2

Please sign in to comment.