Skip to content

Commit

Permalink
Adding behavior to fetch_table to allow fetch_table_bkchin to turn of…
Browse files Browse the repository at this point in the history
…f warning
  • Loading branch information
cbedwards-dfw committed Dec 13, 2024
1 parent 47f3a86 commit 1f93dde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions R/fetch_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#' tibble.
#' @param fram_db FRAM database object
#' @param table_name Table to be fetched. If not given, a list of options will be printed
#' @param warn Print a warning when fetching BackwardsFRAM table from a Chinook database? Defaults to `TRUE`.
#' @export
#' @examples
#' \dontrun{fram_db |> fetch_table('Mortality')}
#'

fetch_table <- function(fram_db, table_name = NULL){
fetch_table <- function(fram_db, table_name = NULL, warn = TRUE){
## adding input checking
validate_fram_db(fram_db)
all_tables = provide_table_names(is_full = TRUE)
Expand Down Expand Up @@ -56,7 +57,7 @@ fetch_table <- function(fram_db, table_name = NULL){
fram_clean_tables()
attr(output_table, 'species') <- fram_db$fram_db_species

if(fram_db$fram_db_species == "CHINOOK" & table_name == "BackwardsFRAM"){
if(warn & fram_db$fram_db_species == "CHINOOK" & table_name == "BackwardsFRAM"){
cli::cli_alert_danger("Chinook BackwardsFRAM tables use different numbering for stock_id!\n This can cause problems when merging with other tables!\n Recommend fetch_table_bkchin() instead.")
}

Expand Down Expand Up @@ -96,7 +97,8 @@ fetch_table_bkchin <- function(fram_db){
cli::cli_abort("`fetch_table_bkchin()` only appropriate for CHINOOK databases, not {fram_db$fram_db_species} database.")
}

output_table <- fetch_table(fram_db, table_name = "BackwardsFRAM") |>
output_table <- fetch_table(fram_db, table_name = "BackwardsFRAM",
warn = FALSE) |>
dplyr::rename(bk_stock_id = .data$stock_id) |>
dplyr::left_join(framrosetta::bk_lookup_chin, by = "bk_stock_id")

Expand Down
4 changes: 3 additions & 1 deletion man/fetch_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f93dde

Please sign in to comment.