diff --git a/DESCRIPTION b/DESCRIPTION index 78e4771..3b5d111 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,52 +2,45 @@ Package: hakedataUSA Title: Extract USA Data for Pacific Hake Version: 2022.0.1 Authors@R: c( - person(given = c("Kelli", "F."), - family = "Johnson", - role = c("aut", "cre"), - email = "kelli.johnson@noaa.gov", + person(c("Kelli", "F."), "Johnson", , "kelli.johnson@noaa.gov", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-5149-451X")), - person(given = c("Aaron", "M."), - family = "Berger", - role = "aut"), - person(given = c("Ian", "G."), - family = "Taylor", - role = "ctb"), - person(given = c("Alan", "C."), - family = "Hicks", - role = "ctb"), - person(given = c("Andi"), - family = "Stephens", - role = "ctb")) -Description: Extract data from the two data warehouses, i.e., North Pacific Database (NORPAC) and Pacific Fisheries Information Network (PacFIN), used to store data for the Pacific Fisheries Management Council (PFMC). + person(c("Aaron", "M."), "Berger", role = "aut"), + person(c("Ian", "G."), "Taylor", role = "ctb"), + person(c("Alan", "C."), "Hicks", role = "ctb"), + person("Andi", "Stephens", role = "ctb") + ) +Description: Extract data from the two data warehouses, i.e., North + Pacific Database (NORPAC) and Pacific Fisheries Information Network + (PacFIN), used to store data for the Pacific Fisheries Management + Council (PFMC). License: What license it uses -Encoding: UTF-8 -LazyData: true -Suggests: - knitr, - rmarkdown, - RODBC, - testthat +Depends: + R (>= 2.10) Imports: - magrittr, dplyr, fs, ggplot2, glue, graphics, grDevices, + magrittr, mapdata, maps, plyr, - RColorBrewer, r4ss, + RColorBrewer, readxl, stats, tidyr, tools +Suggests: + knitr, + rmarkdown, + RODBC, + testthat Remotes: - github::r4ss/r4ss -RoxygenNote: 7.2.3 + github::r4ss/r4ss +Encoding: UTF-8 +LazyData: true Roxygen: list(markdown = TRUE) -Depends: - R (>= 2.10) +RoxygenNote: 7.2.3 diff --git a/R/plot_boxplot.R b/R/plot_boxplot.R index 85f2826..bc6540b 100644 --- a/R/plot_boxplot.R +++ b/R/plot_boxplot.R @@ -39,7 +39,7 @@ get_depth_by_year <- function(d, median = 4, upperhinge = 5, upper95 = 6 ) - if(!is.null(yrs)){ + if (!is.null(yrs)) { dpth <- dpth %>% dplyr::filter(year %in% yrs) } @@ -62,7 +62,7 @@ get_rate_by_month <- function(d, median = 5, upperhinge = 6, upper95 = 7 ) - if(!is.null(yrs)){ + if (!is.null(yrs)) { dpth <- dpth %>% dplyr::filter(year %in% yrs) } diff --git a/R/process_age-.R b/R/process_age-.R index d18846b..84ccc58 100644 --- a/R/process_age-.R +++ b/R/process_age-.R @@ -69,7 +69,7 @@ process_age_sea <- function(atsea.ages = get_local(file = "atsea.ages.Rdat"), dplyr::mutate(dplyr::across( dplyr::everything(), .fns = \(x) tidyr::replace_na(x, 0) - ))|> + )) |> tidyr::nest(gg = -"vesseltype") |> dplyr::mutate( lower_name = tolower(vesseltype), @@ -153,7 +153,7 @@ process_age_shore <- function(page = get_local("page.Rdat"), dplyr::mutate(dplyr::across( dplyr::everything(), .fns = \(x) tidyr::replace_na(x, 0) - ))|> + )) |> utils::write.csv( file = fs::path(hakedata_wd(), "us-sb-age-raw.csv"), row.names = FALSE, diff --git a/R/process_catch-.R b/R/process_catch-.R index 2aa9301..e33970e 100644 --- a/R/process_catch-.R +++ b/R/process_catch-.R @@ -257,7 +257,6 @@ process_catch_norpac <- function(ncatch = get_local(file = "norpac_catch.Rdat"), process_catch_pacfin <- function(pcatch = get_local(file = "pacfin_catch.Rdat"), nyears = 5, savedir = hakedata_wd()) { - # FLEET XXX is in the hake assessment as shore-based catches, # although 1986 differs from data used # database 1986 3431.9436 diff --git a/R/process_weight_at_age-.R b/R/process_weight_at_age-.R index 61123d1..fbcd7d6 100644 --- a/R/process_weight_at_age-.R +++ b/R/process_weight_at_age-.R @@ -13,8 +13,8 @@ process_weight_at_age_survey <- function(savedir = hakedata_wd()) { # Custom function only needed inside this function for survey data read_mutate_join <- function(x, y) { if (!grepl("xlsx", x)) { - x_data <- suppressWarnings(readxl::read_xls(x)) - y_data <- suppressWarnings(readxl::read_xls(y)) + x_data <- suppressWarnings(readxl::read_xls(x)) + y_data <- suppressWarnings(readxl::read_xls(y)) } else { x_data <- suppressWarnings(readxl::read_excel(x)) y_data <- suppressWarnings(readxl::read_excel(y)) @@ -48,24 +48,24 @@ process_weight_at_age_survey <- function(savedir = hakedata_wd()) { yy, by = "haul" ) |> - dplyr::transmute( - Source = dplyr::case_when( - basename(dirname(x)) == "US" ~ "U.S. Acoustic", - basename(dirname(x)) == "CAN" ~ "Canada Acoustic", - TRUE ~ "Unknown Acoustic" - ), - Weight_kg = weight, - Sex = Sex2, - Age_yrs = age, - Length_cm = length, - Month = as.numeric(format(as.Date(hb_date_time, f = "%m/%d/%Y"), "%m")), - Year = as.numeric(format(as.Date(hb_date_time, f = "%m/%d/%Y"), "%Y")) - ) |> - dplyr::mutate( - Year = ifelse(Year < 2000, Year + 2000, Year) - ) |> - dplyr::filter(!is.na(Age_yrs)) |> - dplyr::filter(!is.na(Weight_kg)) + dplyr::transmute( + Source = dplyr::case_when( + basename(dirname(x)) == "US" ~ "U.S. Acoustic", + basename(dirname(x)) == "CAN" ~ "Canada Acoustic", + TRUE ~ "Unknown Acoustic" + ), + Weight_kg = weight, + Sex = Sex2, + Age_yrs = age, + Length_cm = length, + Month = as.numeric(format(as.Date(hb_date_time, f = "%m/%d/%Y"), "%m")), + Year = as.numeric(format(as.Date(hb_date_time, f = "%m/%d/%Y"), "%Y")) + ) |> + dplyr::mutate( + Year = ifelse(Year < 2000, Year + 2000, Year) + ) |> + dplyr::filter(!is.na(Age_yrs)) |> + dplyr::filter(!is.na(Weight_kg)) stopifnot(!any(is.na(together[["Year"]]))) return(together) } @@ -84,7 +84,7 @@ process_weight_at_age_survey <- function(savedir = hakedata_wd()) { "/20[12][0-9]/[CANUS]{2,3}|/2009/[CANUS]{2,3}", value ) - ) |> + ) |> dplyr::mutate( bio_file = purrr::map_chr( value, @@ -223,9 +223,9 @@ process_weight_at_age <- function(dir = hakedata_wd(), # save on size, contains all US samples in LWAdata_1975to2007.csv, so # eliminated that file. files_weights <- fs::path( - ext = "csv", - dir, - c("survey-weight-at-age", "us-weight-at-age", "can-weight-at-age") + ext = "csv", + dir, + c("survey-weight-at-age", "us-weight-at-age", "can-weight-at-age") ) dat <- purrr::map_dfr( files_weights, diff --git a/README.Rmd b/README.Rmd index 40d8c88..79423e8 100644 --- a/README.Rmd +++ b/README.Rmd @@ -32,15 +32,15 @@ for the assessment of Pacific Hake. 1. Next, load the package. This can be accomplished through GitHub (first chunk) or using a local clone (second chunk). ```{r installation-github} - chooseCRANmirror(ind = 1) - # install.packages("pak") - pak::pak("pacific-hake/hakedataUSA") - library(hakedataUSA) +chooseCRANmirror(ind = 1) +# install.packages("pak") +pak::pak("pacific-hake/hakedataUSA") +library(hakedataUSA) ``` ```{r installation-local} - chooseCRANmirror(ind = 1) - stopifnot(basename(getwd()) == "hakedataUSA") - devtools::load_all() +chooseCRANmirror(ind = 1) +stopifnot(basename(getwd()) == "hakedataUSA") +devtools::load_all() ``` 1. The path to where all of the raw output will be saved is stored in an internal function, i.e., `hakedata_wd()`. Try it out, see if it works for diff --git a/man/process_weight_at_age.Rd b/man/process_weight_at_age.Rd index 57b878f..3496f3e 100644 --- a/man/process_weight_at_age.Rd +++ b/man/process_weight_at_age.Rd @@ -5,7 +5,7 @@ \title{Create weight-at-age files for hake assessment} \usage{ process_weight_at_age( - dir = fs::path(hakedata_wd(), "length-weight-age"), + dir = hakedata_wd(), maxage = 15, yrs = 2008:hakedata_year(), navgyears = 5,