diff --git a/DESCRIPTION b/DESCRIPTION index 802c872..598ef34 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,19 +3,13 @@ Package: nwfscDiscard Title: Northwest Fisheries Science Center Version: 2.0 Date: 2018-04-13 -Authors@R: c( - person( - given = c("Chantel", "R."), - family = "Wetzel", , - email = "chantel.wetzel@noaa.gov", - role = c("aut", "cre"), - comment = c(ORCID = "0000-0002-7573-8240") - ) - ) -Description: Northwest Fisheries Science Center WCGOP data processing for use in - West Coast groundfish assessments. All scripts to process the available data are - publicly available but the data are stored in a private location to maintain - confidentiality. +Authors@R: + person(c("Chantel", "R."), "Wetzel", , "chantel.wetzel@noaa.gov", role = c("aut", "cre"), + comment = c(ORCID = "0000-0002-7573-8240")) +Description: Northwest Fisheries Science Center WCGOP data processing for + use in West Coast groundfish assessments. All scripts to process the + available data are publicly available but the data are stored in a + private location to maintain confidentiality. License: GPL (>=3) Depends: R (>= 4.2) diff --git a/R/bootstrap_discard.R b/R/bootstrap_discard.R index e932521..22964da 100644 --- a/R/bootstrap_discard.R +++ b/R/bootstrap_discard.R @@ -110,7 +110,8 @@ boostrap_discard <- function( all_boot_data <- dplyr::left_join( y = boot_out, x = cf_data, - by = c("fleet", "year")) |> + by = c("fleet", "year") + ) |> dplyr::filter(n_vessels >= 3) |> data.frame() diff --git a/R/calc_comps.R b/R/calc_comps.R index c4280ec..907421b 100644 --- a/R/calc_comps.R +++ b/R/calc_comps.R @@ -49,7 +49,7 @@ calc_comps <- function( dplyr::ungroup() |> dplyr::filter(n_by_year != 0) |> dplyr::mutate( - prop_numbers = 100 * n/n_by_year, + prop_numbers = 100 * n / n_by_year, prop_weighted = 100 * weighted / w_by_year ) @@ -62,7 +62,7 @@ calc_comps <- function( comps_out_sexed <- comps_out_unsexed <- all_comps <- NULL out <- list() - if (any(comps[,"sex"] == "U")) { + if (any(comps[, "sex"] == "U")) { sub <- comps[comps$sex == "U", ] keep <- which(apply(sub[, 6:ncol(sub)], 1, sum) != 0) filter_comps <- sub[keep, ] @@ -77,7 +77,8 @@ calc_comps <- function( vessels = length(unique(drvid)), ratio = fish / trips, nsamp = round(dplyr::case_when( - ratio < 44 ~ trips + 0.138 * fish, .default = 7.06 * hauls + ratio < 44 ~ trips + 0.138 * fish, + .default = 7.06 * hauls ), 0), fleet = paste0(unique(gear_groups), "-", unique(fleet_groups)) ) |> @@ -108,15 +109,17 @@ calc_comps <- function( vessels = length(unique(drvid)), ratio = fish / trips, nsamp = round(dplyr::case_when( - ratio < 44 ~ trips + 0.138 * fish, .default = 7.06 * hauls + ratio < 44 ~ trips + 0.138 * fish, + .default = 7.06 * hauls ), 0), fleet = paste0(unique(gear_groups), "-", unique(fleet_groups)) ) |> data.frame() - comps_sexed <- cbind( + comps_sexed <- cbind( comps[comps$sex == "F", 6:ncol(comps)], - comps[comps$sex == "M", 6:ncol(comps)]) + comps[comps$sex == "M", 6:ncol(comps)] + ) remove <- which(apply(comps_sexed, 1, sum) == 0) filter_comps <- comps_sexed[-remove, ] @@ -134,7 +137,7 @@ calc_comps <- function( } if (comp_column == "age") { - if (!is.null(comps_out_unsexed)){ + if (!is.null(comps_out_unsexed)) { comps_out_unsexed <- cbind( comps_out_unsexed[, 1:5], "age_error", @@ -147,7 +150,7 @@ calc_comps <- function( colnames(comps_out_unsexed)[6:9] <- c("age_error", "age_low", "age_high", "input_n") out$unsexed <- comps_out_unsexed } - if (!is.null(comps_out_sexed)){ + if (!is.null(comps_out_sexed)) { comps_out_sexed <- cbind( comps_out_sexed[, 1:5], "age_error", @@ -171,24 +174,25 @@ calc_comps <- function( vessels = length(unique(drvid)), ratio = fish / trips, nsamp = round(dplyr::case_when( - ratio < 44 ~ trips + 0.138 * fish, .default = 7.06 * hauls + ratio < 44 ~ trips + 0.138 * fish, + .default = 7.06 * hauls ), 0) ) |> dplyr::select(-ratio) |> data.frame() if (!is.null(dir)) { - if (dim(sample_size)[1] > 0 ) { + if (dim(sample_size)[1] > 0) { write.csv(sample_size, - file = file.path(dir, paste0("biological_sample_sizes_", comp_column, ".csv")), - row.names = FALSE + file = file.path(dir, paste0("biological_sample_sizes_", comp_column, ".csv")), + row.names = FALSE ) } if (!is.null(all_comps)) { write.csv(all_comps, - file = file.path(dir, paste0("biological_discard_", comp_column, "s.csv")), - row.names = FALSE + file = file.path(dir, paste0("biological_discard_", comp_column, "s.csv")), + row.names = FALSE ) } } diff --git a/R/get_biological_data.R b/R/get_biological_data.R index 1283e67..bbcfa0a 100644 --- a/R/get_biological_data.R +++ b/R/get_biological_data.R @@ -95,13 +95,16 @@ get_biological_data <- function( dplyr::mutate( exp1 = dplyr::case_when( !is.na(species_number) | !is.na(bio_specimen_count) ~ species_number / bio_specimen_count, - .default = 0), + .default = 0 + ), exp_weight = dplyr::case_when( is.na(exp_sp_wt) ~ (species_weight / hooks_sampled) * total_hooks, - .default = exp_sp_wt), + .default = exp_sp_wt + ), exp2 = dplyr::case_when( !is.na(species_weight) ~ exp_weight / species_weight, - .default = 0), + .default = 0 + ), wghtd_freq = frequency * exp1 * exp2 ) diff --git a/R/run.R b/R/run.R index 01a7549..11b23e1 100644 --- a/R/run.R +++ b/R/run.R @@ -26,9 +26,8 @@ run <- function( biological_data, em_catch_data = NULL, save_loc = NULL, - n_boot = 10000 - ) { - if(!is.null(em_catch_data)) { + n_boot = 10000) { + if (!is.null(em_catch_data)) { do_em <- TRUE } else { do_em <- FALSE