-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify project to read in any assessment data from the GitHub
hake-assessment repository * Working towards no more local CSV files and update to 2024 RDS structure
- Loading branch information
Showing
17 changed files
with
135 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
#' Extract the catch by country using the assessment landings file | ||
#' | ||
#' @param data_csv_dir The directory in which the assessment csv files containing catch by month are located | ||
#' @param ss_model_data_csv_dir The directory in which the assessment csv | ||
#' files containing catch by month are located. Can be a URL | ||
#' @param ... Ansorbs arguments meant for other functions | ||
#' | ||
#' @return A data frame with three columns, the year, the Canadian catch and the US catch | ||
#' @export | ||
#' @importFrom readr read_csv | ||
extract_catch_country <- function(data_csv_dir = NULL){ | ||
extract_catch_country <- function(ss_model_data_csv_dir = NULL, | ||
...){ | ||
|
||
fn <- file.path(data_csv_dir, "landings-tac-history.csv") | ||
if(!file.exists(fn)){ | ||
fn <- file.path(ss_model_data_csv_dir, "landings-tac-history.csv") | ||
|
||
if(!files_exist(fn)){ | ||
cat(red(symbol$cross), | ||
red(paste0("The data file ", fn, " does not exist. catch_country object is NULL\n"))) | ||
red(paste0("The data file:\n`", fn, "`\n does not exist. ", | ||
"`catch_country` object is NULL"))) | ||
return(NULL) | ||
} | ||
d <- read_csv(fn, col_types = cols()) | ||
|
||
can <- d %>% | ||
select(Year, CAN_forgn, CAN_JV, CAN_Shoreside) %>% | ||
mutate(can = CAN_forgn + CAN_JV + CAN_Shoreside) %>% | ||
can <- d |> | ||
mutate(can = `Canada Foreign` + | ||
`Canada Joint-venture` + | ||
`Canada Shoreside` + | ||
`Canada Freezer-trawler`) |> | ||
select(year = Year, can) | ||
usa <- d %>% | ||
select(Year, US_foreign, US_JV, atSea_US_MS, atSea_US_CP, US_shore, USresearch) %>% | ||
mutate(usa = US_foreign + US_JV + atSea_US_MS + atSea_US_CP + US_shore + USresearch) %>% | ||
|
||
usa <- d |> | ||
mutate(usa = `U.S. Foreign` + | ||
`U.S. Joint-venture` + | ||
`U.S. Mothership` + | ||
`U.S. Catcher-processor` + | ||
`U.S. Shore-based` + | ||
`U.S. Research`) |> | ||
select(year = Year, usa) | ||
|
||
j <- can %>% | ||
out <- can |> | ||
left_join(usa, by = "year") | ||
|
||
# TODO: This is hardwired to try to match the output of Nis' code. The data in the catch_per_country.csv | ||
# file are the same as in the landings-tac-history.csv file up to 2005, when they diverge. Nis used | ||
# catch_per_country.csv. To return to correct, comment the statement below out and return j | ||
k <- read_csv(system.file("extdata/csv-data/catch_per_country.csv", | ||
package = "pacifichakemse", | ||
mustWork = TRUE), | ||
col_types = cols()) %>% | ||
rename(can = Can, us = US) %>% | ||
select(year, can, us) | ||
|
||
#df$Catch.country <- as.matrix(Catch.country[,2:3])[,c(2,1)] | ||
as.matrix(k) | ||
out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.