From ffd9bc6a4adb3fbb1a287e5534c7e26407ebbf2d Mon Sep 17 00:00:00 2001 From: andybeet <22455149+andybeet@users.noreply.github.com> Date: Thu, 24 Feb 2022 15:03:45 -0500 Subject: [PATCH 1/2] added error check for metric argument spelling added group_by to fix filteing bug --- R/get_latest_metrics.r | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/get_latest_metrics.r b/R/get_latest_metrics.r index 9c4d934..3341ab6 100644 --- a/R/get_latest_metrics.r +++ b/R/get_latest_metrics.r @@ -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")) @@ -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 %>% From a0924b699eeac5b078236ed6c4db1dcad0a41a6c Mon Sep 17 00:00:00 2001 From: andybeet <22455149+andybeet@users.noreply.github.com> Date: Thu, 24 Feb 2022 15:09:12 -0500 Subject: [PATCH 2/2] updated versioning due to bug --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 801b105..e4a9bb4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "andrew.beet@noaa.gov", diff --git a/NEWS.md b/NEWS.md index c45e9e9..b5ff946 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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