From 9fde9b68983926a1141547b98088b7835dd65ff4 Mon Sep 17 00:00:00 2001 From: Ty Garber Date: Sun, 17 Mar 2024 21:00:58 -0700 Subject: [PATCH 1/4] moved the whale to the package startup --- R/integrity.R | 10 ---------- R/zzz.R | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 R/zzz.R diff --git a/R/integrity.R b/R/integrity.R index 0ce6817..cdd7271 100644 --- a/R/integrity.R +++ b/R/integrity.R @@ -225,16 +225,6 @@ welcome <- function(con){ dplyr::filter(.data$run_time_date == max(runs$run_time_date)) |> dplyr::pull(.data$run_name) - cli::cli_text(cat(cli::col_black(" - . - \":\" - ___:____ |\"\\/\"| - ,' `. \\ / - | O \\___/ | - ~^~^~^~^~^~^~^~^~^~^~^~^~ - S.R.K.W - "))) - cli::cli_text(cat(cli::col_blue('Database Species: '), cli::col_grey(species))) cli::cli_text(cat(cli::col_blue('Run Count: '), cli::col_grey(run_count))) cli::cli_text(cat(cli::col_blue('Last Run Date: '), cli::col_grey(last_run))) diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..d889662 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,20 @@ +.onAttach <- function(libname, pkgname) { + startup_message() +} + + +startup_message <- function(){ + cli::cli_text(cat( + cli::col_black( + " + . + \":\" + ___:____ |\"\\/\"| + ,' `. \\ / + | O \\___/ | + ~^~^~^~^~^~^~^~^~^~^~^~^~ + framrsquared 0.1 + " + ) + )) +} From 7814a0279ff19845375b143bae4061b3e4a927b3 Mon Sep 17 00:00:00 2001 From: Ty Garber Date: Mon, 18 Mar 2024 08:40:37 -0700 Subject: [PATCH 2/4] coho mort chart will now accept multiple areas --- R/report_fishery_mortality.R | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/R/report_fishery_mortality.R b/R/report_fishery_mortality.R index b5999a6..39ccf01 100644 --- a/R/report_fishery_mortality.R +++ b/R/report_fishery_mortality.R @@ -221,23 +221,11 @@ coho_stock_mortality_time_step <- function(fram_db, run_id = NULL, stock_id = NU dplyr::select(.data$fishery_id, .data$fishery_name) - stocks <- fram_db |> - fetch_table('Stock') |> - dplyr::filter(.data$species == fram_db$fram_db_species) |> - dplyr::select(.data$stock_id, .data$stock_name) - - # lut for display of fishery - fisheries <- fram_db |> - fetch_table('Fishery') |> - dplyr::filter(.data$species == fram_db$fram_db_species) |> - dplyr::select(.data$fishery_id, .data$fishery_name) - - mortality <- fram_db |> fetch_table('Mortality') |> dplyr::filter(.data$run_id == .env$run_id, - .data$stock_id == .env$stock_id) |> - dplyr::group_by(.data$run_id, .data$stock_id, .data$time_step, .data$fishery_id) |> + .data$stock_id %in% .env$stock_id) |> + dplyr::group_by(.data$run_id, .data$time_step, .data$fishery_id) |> dplyr::summarize( dplyr::across(c(.data$landed_catch:.data$drop_off, .data$msf_landed_catch:.data$msf_drop_off), \(x) sum(x)), @@ -246,7 +234,7 @@ coho_stock_mortality_time_step <- function(fram_db, run_id = NULL, stock_id = NU total_mort = .data$landed_catch + .data$non_retention + .data$shaker + .data$drop_off + .data$msf_landed_catch + .data$msf_non_retention + .data$msf_shaker + .data$msf_drop_off ) |> - dplyr::select(.data$run_id, .data$stock_id, .data$fishery_id, .data$total_mort, .data$time_step) + dplyr::select(.data$run_id, .data$fishery_id, .data$total_mort, .data$time_step) run_name <- fram_db |> fetch_table('RunID') |> @@ -254,11 +242,13 @@ coho_stock_mortality_time_step <- function(fram_db, run_id = NULL, stock_id = NU dplyr::pull(.data$run_name) stock_name <- stocks |> - dplyr::filter(.data$stock_id == .env$stock_id) |> + dplyr::filter(.data$stock_id %in% .env$stock_id) |> dplyr::pull(.data$stock_name) + stock_name <- paste0(stock_name, collapse = ', ') + mort_table <- mortality |> - dplyr::group_by(.data$run_id, .data$stock_id, .data$fishery_id) |> + dplyr::group_by(.data$run_id, .data$fishery_id) |> dplyr::summarize( dplyr::across(.data$total_mort, \(x) sum(x)), .groups='drop') |> @@ -271,7 +261,13 @@ coho_stock_mortality_time_step <- function(fram_db, run_id = NULL, stock_id = NU top_fish |> dplyr::inner_join(fisheries, by = 'fishery_id') |> - ggplot2::ggplot(ggplot2::aes(.data$total_mort, stats::reorder(.data$fishery_name, .data$total_mort, function(x){ sum(x) }), fill = factor(.data$time_step))) + + ggplot2::ggplot(ggplot2::aes( + .data$total_mort, + stats::reorder(.data$fishery_name, .data$total_mort, function(x) { + sum(x) + }), + fill = factor(.data$time_step) + )) + ggplot2::geom_col(alpha = .6) + ggplot2::scale_fill_brewer(palette = 'Set1') + ggplot2::labs( @@ -280,7 +276,7 @@ coho_stock_mortality_time_step <- function(fram_db, run_id = NULL, stock_id = NU y = 'Fishery' ) + ggplot2::theme(legend.title = ggplot2::element_blank()) - } + From c203c811260f4ceb9ceba63104d0a7d0f8003c51 Mon Sep 17 00:00:00 2001 From: Ty Garber Date: Mon, 18 Mar 2024 09:04:29 -0700 Subject: [PATCH 3/4] truns for fisheries grouping consistent with TAMM output --- NAMESPACE | 2 ++ R/truns.R | 32 ++++++++++++++++++++++++++++++++ man/truns_fisheries.Rd | 20 ++++++++++++++++++++ man/truns_stocks.Rd | 20 ++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 R/truns.R create mode 100644 man/truns_fisheries.Rd create mode 100644 man/truns_stocks.Rd diff --git a/NAMESPACE b/NAMESPACE index 06c242e..a0d09b0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -46,5 +46,7 @@ export(remove_run) export(run_info) export(statistical_week) export(stock_mortality) +export(truns_fisheries) +export(truns_stocks) importFrom(rlang,.data) importFrom(rlang,.env) diff --git a/R/truns.R b/R/truns.R new file mode 100644 index 0000000..3c4e409 --- /dev/null +++ b/R/truns.R @@ -0,0 +1,32 @@ +#' Returns a dataframe with stocks defined +#' by the TRuns report driver +#' @param db_path Path to a FRAM database. +#' @export +#' @examples +#' \dontrun{truns <- truns_stocks(fram_db)} +#' +truns_stocks <- function(fram_db){ + fram_db |> + fetch_table('ReportDriver') |> + dplyr::filter(driver_name == 'PSCTRuns.DRV') |> + dplyr::select(stock_id = option1, stock_name = option5) |> + tidyr::separate_longer_delim(stock_id, ',') |> + dplyr::mutate(across(stock_id, as.numeric)) +} + +#' Returns a dataframe with fisheries defined +#' by the TRuns report driver +#' @param db_path Path to a FRAM database. +#' @export +#' @examples +#' \dontrun{truns <- truns_fisheries(fram_db)} +#' +truns_fisheries <- function(fram_db){ + fram_db |> + fetch_table('ReportDriver') |> + dplyr::filter(driver_name == 'PSCTRuns.DRV') |> + dplyr::select(fishery_id = option2, stock_name = option5) |> + tidyr::separate_longer_delim(fishery_id, ',') |> + dplyr::mutate(across(fishery_id, as.numeric)) +} + diff --git a/man/truns_fisheries.Rd b/man/truns_fisheries.Rd new file mode 100644 index 0000000..5342a92 --- /dev/null +++ b/man/truns_fisheries.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/truns.R +\name{truns_fisheries} +\alias{truns_fisheries} +\title{Returns a dataframe with fisheries defined +by the TRuns report driver} +\usage{ +truns_fisheries(fram_db) +} +\arguments{ +\item{db_path}{Path to a FRAM database.} +} +\description{ +Returns a dataframe with fisheries defined +by the TRuns report driver +} +\examples{ +\dontrun{truns <- truns_fisheries(fram_db)} + +} diff --git a/man/truns_stocks.Rd b/man/truns_stocks.Rd new file mode 100644 index 0000000..67d0897 --- /dev/null +++ b/man/truns_stocks.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/truns.R +\name{truns_stocks} +\alias{truns_stocks} +\title{Returns a dataframe with stocks defined +by the TRuns report driver} +\usage{ +truns_stocks(fram_db) +} +\arguments{ +\item{db_path}{Path to a FRAM database.} +} +\description{ +Returns a dataframe with stocks defined +by the TRuns report driver +} +\examples{ +\dontrun{truns <- truns_stocks(fram_db)} + +} From ac9acdceb8bdd68c94d5931418665c2599ee495a Mon Sep 17 00:00:00 2001 From: Ty Garber Date: Mon, 18 Mar 2024 09:14:53 -0700 Subject: [PATCH 4/4] making sure passes R CMD CHECK --- R/truns.R | 20 ++++++++++---------- man/truns_fisheries.Rd | 2 +- man/truns_stocks.Rd | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/truns.R b/R/truns.R index 3c4e409..23148cd 100644 --- a/R/truns.R +++ b/R/truns.R @@ -1,6 +1,6 @@ #' Returns a dataframe with stocks defined #' by the TRuns report driver -#' @param db_path Path to a FRAM database. +#' @param fram_db FRAM database object #' @export #' @examples #' \dontrun{truns <- truns_stocks(fram_db)} @@ -8,15 +8,15 @@ truns_stocks <- function(fram_db){ fram_db |> fetch_table('ReportDriver') |> - dplyr::filter(driver_name == 'PSCTRuns.DRV') |> - dplyr::select(stock_id = option1, stock_name = option5) |> - tidyr::separate_longer_delim(stock_id, ',') |> - dplyr::mutate(across(stock_id, as.numeric)) + dplyr::filter(.data$driver_name == 'PSCTRuns.DRV') |> + dplyr::select(stock_id = .data$option1, stock_name = .data$option5) |> + tidyr::separate_longer_delim(.data$stock_id, ',') |> + dplyr::mutate(dplyr::across(.data$stock_id, as.numeric)) } #' Returns a dataframe with fisheries defined #' by the TRuns report driver -#' @param db_path Path to a FRAM database. +#' @param fram_db FRAM database object #' @export #' @examples #' \dontrun{truns <- truns_fisheries(fram_db)} @@ -24,9 +24,9 @@ truns_stocks <- function(fram_db){ truns_fisheries <- function(fram_db){ fram_db |> fetch_table('ReportDriver') |> - dplyr::filter(driver_name == 'PSCTRuns.DRV') |> - dplyr::select(fishery_id = option2, stock_name = option5) |> - tidyr::separate_longer_delim(fishery_id, ',') |> - dplyr::mutate(across(fishery_id, as.numeric)) + dplyr::filter(.data$driver_name == 'PSCTRuns.DRV') |> + dplyr::select(fishery_id = .data$option2, stock_name = .data$option5) |> + tidyr::separate_longer_delim(.data$ishery_id, ',') |> + dplyr::mutate(dplyr::across(.data$fishery_id, as.numeric)) } diff --git a/man/truns_fisheries.Rd b/man/truns_fisheries.Rd index 5342a92..b5986fc 100644 --- a/man/truns_fisheries.Rd +++ b/man/truns_fisheries.Rd @@ -8,7 +8,7 @@ by the TRuns report driver} truns_fisheries(fram_db) } \arguments{ -\item{db_path}{Path to a FRAM database.} +\item{fram_db}{FRAM database object} } \description{ Returns a dataframe with fisheries defined diff --git a/man/truns_stocks.Rd b/man/truns_stocks.Rd index 67d0897..441869f 100644 --- a/man/truns_stocks.Rd +++ b/man/truns_stocks.Rd @@ -8,7 +8,7 @@ by the TRuns report driver} truns_stocks(fram_db) } \arguments{ -\item{db_path}{Path to a FRAM database.} +\item{fram_db}{FRAM database object} } \description{ Returns a dataframe with stocks defined