From 14eda343f54dbde2819af8e24079af238ef6e10e Mon Sep 17 00:00:00 2001 From: Chantel Wetzel Date: Wed, 8 May 2024 06:38:16 -0700 Subject: [PATCH 1/6] add template param descriptions --- man-roxygen/ageErr.R | 3 +++ man-roxygen/agehigh.R | 3 +++ man-roxygen/agelow.R | 3 +++ man-roxygen/dir.R | 2 +- man-roxygen/fleet.R | 3 +++ man-roxygen/month.R | 4 ++++ man-roxygen/partition.R | 4 ++++ man-roxygen/printfolder.R | 3 +++ man-roxygen/sex.R | 5 +++++ man-roxygen/strat.df.R | 3 +++ man-roxygen/strat.vars.R | 3 +++ 11 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 man-roxygen/ageErr.R create mode 100644 man-roxygen/agehigh.R create mode 100644 man-roxygen/agelow.R create mode 100644 man-roxygen/fleet.R create mode 100644 man-roxygen/month.R create mode 100644 man-roxygen/partition.R create mode 100644 man-roxygen/printfolder.R create mode 100644 man-roxygen/sex.R create mode 100644 man-roxygen/strat.df.R create mode 100644 man-roxygen/strat.vars.R diff --git a/man-roxygen/ageErr.R b/man-roxygen/ageErr.R new file mode 100644 index 0000000..fa7c1be --- /dev/null +++ b/man-roxygen/ageErr.R @@ -0,0 +1,3 @@ +#' @param ageErr Single interget value of ageing error +#' vector to apply to the age data based on +#' Stock Synthesis. Default "Enter". diff --git a/man-roxygen/agehigh.R b/man-roxygen/agehigh.R new file mode 100644 index 0000000..baccca9 --- /dev/null +++ b/man-roxygen/agehigh.R @@ -0,0 +1,3 @@ +#' @param agehigh Upper age bin for all age composition data based on the expected +#' format for Stock Synthesis. Default value of -1 which translates to the highest +# age bin. diff --git a/man-roxygen/agelow.R b/man-roxygen/agelow.R new file mode 100644 index 0000000..c49bc2a --- /dev/null +++ b/man-roxygen/agelow.R @@ -0,0 +1,3 @@ +#' @param agelow Lower age bin for all age composition data based on the expected +#' format for Stock Synthesis. Default value of -1 which translates to the lowest age +#' bin. diff --git a/man-roxygen/dir.R b/man-roxygen/dir.R index b65b4e1..83fb3c4 100644 --- a/man-roxygen/dir.R +++ b/man-roxygen/dir.R @@ -1,2 +1,2 @@ -#' @param dir directory where ouptut will be saved. The directory where the file should be saved. +#' @param dir Directory where output will be saved. The directory where the file should be saved. #' If dir = NULL no output will be saved. diff --git a/man-roxygen/fleet.R b/man-roxygen/fleet.R new file mode 100644 index 0000000..41bcbe4 --- /dev/null +++ b/man-roxygen/fleet.R @@ -0,0 +1,3 @@ +#' @param fleet A single integer value. A user input fleet +#' number to assign to the fleet column based on the expected +#' format for Stock Synthesis. Default "Enter Fleet". diff --git a/man-roxygen/month.R b/man-roxygen/month.R new file mode 100644 index 0000000..21cfeef --- /dev/null +++ b/man-roxygen/month.R @@ -0,0 +1,4 @@ +#' @param month A single integer value between 1-12. A user input fleet +#' number to assign to the month column based on the expected +#' format for Stock Synthesis. See the Stock Synthesis manual for +#' more information. Default "Enter Month". diff --git a/man-roxygen/partition.R b/man-roxygen/partition.R new file mode 100644 index 0000000..50fd888 --- /dev/null +++ b/man-roxygen/partition.R @@ -0,0 +1,4 @@ +#' @param partition Partition to assign the composition data based on the expected +#' format for Stock Synthesis. Partition of 0 indicates that the composition data +#' include all composition data, 1 for discarded composition data, and 2 for retained +#' fish only. Default of 0. diff --git a/man-roxygen/printfolder.R b/man-roxygen/printfolder.R new file mode 100644 index 0000000..dd1b6cb --- /dev/null +++ b/man-roxygen/printfolder.R @@ -0,0 +1,3 @@ +#' @param printfolder A string that will be appended to `dir`, creating a folder +#' where the output will be saved. If specified as `""`, +#' the output will just be saved directly in `dir`. The default is `"forSS3"`. diff --git a/man-roxygen/sex.R b/man-roxygen/sex.R new file mode 100644 index 0000000..0d9ebe1 --- /dev/null +++ b/man-roxygen/sex.R @@ -0,0 +1,5 @@ +#' @param sex Options of (0, 1, 2, 3). The integer will be used to define the sex column +#' of the returned input for Stock Synthesis and specifies how the +#' composition are treated with respect to sex. See the Stock Synthesis +#' manual for more information. In short, 0 is for unsexed, 1 is females, 2 +#' is males, and 3 is females and males. The default is `3`. diff --git a/man-roxygen/strat.df.R b/man-roxygen/strat.df.R new file mode 100644 index 0000000..e3fa6d9 --- /dev/null +++ b/man-roxygen/strat.df.R @@ -0,0 +1,3 @@ +#' @param strat.df A data frame that defines the strata and provides the +#' calculated areas for each strata returned from [createStrataDF.fn()]. + diff --git a/man-roxygen/strat.vars.R b/man-roxygen/strat.vars.R new file mode 100644 index 0000000..1b089a4 --- /dev/null +++ b/man-roxygen/strat.vars.R @@ -0,0 +1,3 @@ +#' @param strat.vars Variables in both data frame that are used to +#' define the stratas. Default is bottom depth (m) and latitudes (decimal +#' degrees), i.e., `c("Depth_m", "Latitude_dd")`. From c8fedd8deec876d4084b17e5d9e153de7f8bcbf9 Mon Sep 17 00:00:00 2001 From: Chantel Wetzel Date: Wed, 8 May 2024 06:39:18 -0700 Subject: [PATCH 2/6] Clean up description, params, and minor formatting --- R/Biomass.fn.R | 39 ++++++------ R/GetN.fn.R | 41 ++++++------- R/GetStrata.fn.R | 6 +- R/PlotMap.fn.R | 19 +++--- R/PlotPresenceAbsence.fn.R | 28 +++++---- R/PlotSexRatioStrata.fn.R | 19 ++++-- R/StrataAreas.fn.R | 6 +- R/SurveyAFs.fn.R | 121 +++++++++++++++++++++++++------------ R/SurveyAgeAtLen.fn.R | 82 ++++++++++++++++--------- R/SurveyLFs.fn.R | 91 ++++++++++++++++------------ R/UnexpandedAF.fn.R | 42 ++++++++----- R/checkStrata.fn.R | 43 ++++++------- R/createStrataDF.fn.R | 12 +++- R/plotBio.fn.R | 20 ++++-- R/plotBioStrata.fn.R | 29 ++++++--- R/plotFreqData.fn.R | 27 ++++++--- R/plotVarLengthAtAge.fn.R | 29 ++++++--- R/unexpandedLF.fn.R | 43 ++++++++----- 18 files changed, 433 insertions(+), 264 deletions(-) diff --git a/R/Biomass.fn.R b/R/Biomass.fn.R index 12083db..de6f6bb 100644 --- a/R/Biomass.fn.R +++ b/R/Biomass.fn.R @@ -1,24 +1,21 @@ #' Calculates design based estimates from survey data for West Coast surveys. +#' #' The design based index is calculated based on the area of the strata and -#' the mean catch by strata. +#' the mean catch by strata. This function returns a list of design-based +#' estimates by strata and estimates combined across stratas by year. This +#' function is designed to work with data frames pulled from the NWFSC +#' data warehouse using [pull_catch()]. #' See: Gunderson, D.R. and Sample, T.M. 1980. Distribution and abundance of rockfish off Washington, #' Oregon, and California during 1977. Marine Fisheries Review: March - April. #' -#' The variables defining the strata must begin with the name in strat.vars and end with ".1" or ".2" (i.e., Depth_m.1) -#' the strata are assumed to be continuous variables, thus have a lower and upper value defining them. The lower value does not necessarily have to be the same as the previous upper value. -#' the stat.df dataframe is difficult to build up with more than one variable becuase it turns into a design where you have to define all areas, thus repeat the variables for one (like a design) -#' -#' I calculate the variance given stratified sampling theory -#' I work in normal space, then calculate the statistics if B is lognormal -#' This is the Mean Ratio Estimate #' -#' @param dir directory where the output file will be saved -#' @param dat data-frame of the data that has been by the PullCatch.fn -#' @param strat.vars A vector of the strata variable names (i.e., c("Depth_m","Latitude_dd")) -#' @param strat.df a dataframe with the first column the name of the stratum, the second column the area of the stratum, and the remaining columns are the high and low variables defining the strata created by the CreateStrataDF.fn -#' @param printfolder the folder where files will be saved -#' @param outputMedian T/F output median or the mean biomass estimate -#' @param month month for SS +#' @template dir +#' @param dat Data frame of catch data that has been created by the [pull_catch()]. +#' @template strat.vars +#' @template strat.df +#' @template printfolder +#' @param outputMedian Specify whether to output median or the mean biomass estimate. Default `TRUE`. +#' @template month #' @param fleet fleet number for SS #' @template verbose #' @@ -29,8 +26,16 @@ #' @importFrom utils write.csv #' @export -Biomass.fn <- function(dir = NULL, dat, strat.vars = c("Depth_m", "Latitude_dd"), strat.df, printfolder = "forSS", outputMedian = TRUE, - month = NA, fleet = NA, verbose = TRUE) { +Biomass.fn <- function( + dir = NULL, + dat, + strat.vars = c("Depth_m", "Latitude_dd"), + strat.df, + printfolder = "forSS", + outputMedian = TRUE, + month = "Enter month", + fleet = "Enter fleet", + verbose = TRUE) { if (is.null(dat$cpue_kg_km2)) stop("There must be a column called cpue_kg_km2 in the dataframe") diff --git a/R/GetN.fn.R b/R/GetN.fn.R index 47eb436..31aab80 100644 --- a/R/GetN.fn.R +++ b/R/GetN.fn.R @@ -1,4 +1,4 @@ -#' Calculate effN input sample sizes +#' Calculate input sample sizes #' #' @references #' Stewart, I.J. and O.S. Hamel. 2014. @@ -7,10 +7,8 @@ #' Canadian Journal of Fishery and Aquatic Science, 71(4): 581--588. #' [10.1139/cjfas-2013-0289](https://doi.org/10.1139/cjfas-2013-0289). #' -#' @param dir A file path to the main directory where -#' `printfolder` will be created. If `NULL`, which is the default, -#' then no files will be written to the disk. -#' @param dat A `data.frame` of composition data. +#' @template dir +#' @param dat A `data.frame` of composition data created using [pull_bio()]. #' @param type A string specifying whether doing "length" or "age" that is #' used to ensure the sample size is of the correct column and create #' the file name of the saved sheet. @@ -18,8 +16,7 @@ #' will lead to the use of the correct species-specific value for #' the number of unique samples per tow. See the function call for #' allowed values, where the default is `"all"`. -#' @param printfolder A string that will be used to create the name of the -#' folder where files will be saved, i.e., `file.path(dir, printfolder)`. +#' @template printfolder #' @param output A string, where the default is `NULL`, which returns #' only a vector of samples sizes. #' `"summary"`, or any other character string, will return @@ -29,20 +26,22 @@ #' @author Chantel R. Wetzel #' @export -GetN.fn <- function(dir = NULL, - dat, - type = c("length", "age"), - species = c( - "all", - "flatfish", - "shelfrock", - "sloperock", - "thorny", - "others" - ), - printfolder = "forSS", - output = NULL, - verbose = TRUE) { +GetN.fn <- function( + dir = NULL, + dat, + type = c("length", "age"), + species = c( + "all", + "flatfish", + "shelfrock", + "sloperock", + "thorny", + "others" + ), + printfolder = "forSS", + output = NULL, + verbose = TRUE) { + species <- match.arg(species) type <- match.arg(type) n.unq <- NA diff --git a/R/GetStrata.fn.R b/R/GetStrata.fn.R index 62660d2..681e769 100644 --- a/R/GetStrata.fn.R +++ b/R/GetStrata.fn.R @@ -24,9 +24,11 @@ #' to generate the strata returned by this function. Also, see #' convert_strata4vast function in the VASTWestCoast package that converts results #' from this function to strata that can be used within the VAST package. +#' #' @author Chantel Wetzel and Kelli Faye Johnson - -GetStrata.fn <- function(area = "coast") { +#' +GetStrata.fn <- function( + area = "coast") { # development instructions ... find the numbers for each comment # (1) Add your area here in lower-case text diff --git a/R/PlotMap.fn.R b/R/PlotMap.fn.R index 4231d02..256b1f3 100644 --- a/R/PlotMap.fn.R +++ b/R/PlotMap.fn.R @@ -5,7 +5,7 @@ #' #' #' @template dir -#' @param dat An object created by [PullCatch.fn()]. +#' @param dat An object created by [pull_catch()]. #' @param main A string that will be prepended to the name of the saved png #' (i.e., "NWFSC" results in a file called "NWFSC_CPUE_Map.png"). #' @param dopng Deprecated with {nwfscSurvey} 2.1 because providing a non-NULL @@ -35,11 +35,12 @@ #' } #' @import ggplot2 -PlotMap.fn <- function(dir = NULL, - dat, - main = NULL, - dopng = lifecycle::deprecated(), - plot = 1:2) { +PlotMap.fn <- function( + dir = NULL, + dat, + main = NULL, + dopng = lifecycle::deprecated(), + plot = 1:2) { if (lifecycle::is_present(dopng)) { @@ -113,7 +114,7 @@ PlotMap.fn <- function(dir = NULL, print(g) if (!is.null(dir)) { - ggsave(filename = plot_names[1], width = 7, height = 10, units = 'in') + ggsave(filename = plot_names[1], width = 7, height = 10, units = 'in') } } @@ -135,7 +136,7 @@ PlotMap.fn <- function(dir = NULL, x = Longitude_dd, y = Latitude_dd, color = cpue_kg_km2, size = cpue_kg_km2 ), - pch = 1, + pch = 1, col = "lightgrey", alpha = 0.15 ) + @@ -168,7 +169,7 @@ PlotMap.fn <- function(dir = NULL, print(h) if (!is.null(dir)) { - ggsave(filename = plot_names[2], width = 7, height = 10, units = 'in') + ggsave(filename = plot_names[2], width = 7, height = 10, units = 'in') } } } diff --git a/R/PlotPresenceAbsence.fn.R b/R/PlotPresenceAbsence.fn.R index d751bd5..febd94f 100644 --- a/R/PlotPresenceAbsence.fn.R +++ b/R/PlotPresenceAbsence.fn.R @@ -50,19 +50,21 @@ #' # Plot with package data #' PlotPresenceAbsence.fn(catch_nwfsc_combo) #' } -PlotPresenceAbsence.fn <- function(data, - dim = c("depth", "lat", "sex"), - dir = NULL, - dopng = lifecycle::deprecated(), - plot_type = c("proportion", "total"), - depth_min = 50, - depth_max = NULL, - depth_bin_width = 25, - lat_min = 32, - lat_max = 49, - lat_bin_width = 1.0, - add_range_to_main = TRUE, - xlab = NULL) { +PlotPresenceAbsence.fn <- function( + data, + dim = c("depth", "lat", "sex"), + dir = NULL, + dopng = lifecycle::deprecated(), + plot_type = c("proportion", "total"), + depth_min = 50, + depth_max = NULL, + depth_bin_width = 25, + lat_min = 32, + lat_max = 49, + lat_bin_width = 1.0, + add_range_to_main = TRUE, + xlab = NULL) { + lifecycle::deprecate_soft( when = "2.1", what = "PlotPresenceAbsence.fn()", diff --git a/R/PlotSexRatioStrata.fn.R b/R/PlotSexRatioStrata.fn.R index bad6d3d..a9136ea 100644 --- a/R/PlotSexRatioStrata.fn.R +++ b/R/PlotSexRatioStrata.fn.R @@ -1,10 +1,11 @@ #' Function to plot sex ratio by strata #' -#' @param dir directory location for saving the png -#' @param dat data object +#' @template dir +#' @param dat A data frame of length-composition data returned from +#' [pull_bio()]. #' @param type length/age which data type to use -#' @param strat.vars the parameters to stratify the data -#' @param strat.df the created strata matrix with the calculated areas by the createStrataDF.fn function +#' @template strat.vars +#' @template strat.df #' @param circleSize circle size #' @param dopng Deprecated with {nwfscSurvey} 2.1 because providing a non-NULL #' value to `dir` can serve the same purpose as `dopng = TRUE` without the @@ -16,7 +17,15 @@ #' @export #' @seealso \code{\link{StrataFactors.fn}} -PlotSexRatioStrata.fn <- function(dir = NULL, dat, type = "length", strat.vars = c("Depth_m", "Latitude_dd"), strat.df = NULL, circleSize = 0.05, dopng = lifecycle::deprecated(), ...) { +PlotSexRatioStrata.fn <- function( + dir = NULL, + dat, + type = "length", + strat.vars = c("Depth_m", "Latitude_dd"), + strat.df = NULL, + circleSize = 0.05, + dopng = lifecycle::deprecated(), ...) { + if (lifecycle::is_present(dopng)) { lifecycle::deprecate_warn( when = "2.1", diff --git a/R/StrataAreas.fn.R b/R/StrataAreas.fn.R index 785aff6..1fe9495 100644 --- a/R/StrataAreas.fn.R +++ b/R/StrataAreas.fn.R @@ -11,7 +11,7 @@ #' boundaries associated with the strata used in the survey sampling design. #' A latitude break at 40.166667 has also been added to allow strata split #' at that common management boundary near Cape Mendocino. -#' +#' #' @examples #' areaexample <- StrataAreas.fn(data.frame( #' name = LETTERS[1:8], @@ -27,7 +27,7 @@ #' Boundaries are determined by latitude and bottom depth with #' Latitude_dd.1 and Latitude_dd.2 being the #' low and high bound for north to south and -#' Depth_m.1 and Depth_m.2 being the +#' Depth_m.1 and Depth_m.2 being the #' low and high bound for east to west. #' A column of \code{area} can also be included if users want this column to #' be located in a certain order within the data frame, but it is not necessary. @@ -40,8 +40,6 @@ #' @seealso #' See \code{\link{CreateStrataDF.fn}} for a wrapper to this function. #' @export - - StrataAreas.fn <- function( strat.df, df = get(utils::data("SA3_v2021.1", overwrite = TRUE, package = "nwfscSurvey"))) { diff --git a/R/SurveyAFs.fn.R b/R/SurveyAFs.fn.R index 591ba8a..caee10a 100644 --- a/R/SurveyAFs.fn.R +++ b/R/SurveyAFs.fn.R @@ -1,34 +1,41 @@ -#' Expands the ages up to the total stratum area then sums over strata -#' Original Version Written by Allan Hicks 16 March 2009 -#' Modified by Chantel Wetzel to work with the data warehouse data formatting, -#' add additional options of when to apply the sex ratio, and correct some treatment of unsexed fish -#' weighted by sample size and area -#' NOTE: The age bin called F0 or M0 is retained to show proportion of ages smaller than smallest bin -#' You will want to likely add this to your first age bin and delete this before putting in SS, or -#' start the ageBins argument at the 2nd age bin and F0 will be all fish smaller (hence the first age bin) +#' Create marginal age composition data #' -#' @param dir directory this is where the output files will be saved -#' @param datA the biological data frame exctrated from the data warehouse using the PullBio.fn -#' @param datTows the catch data frame extracted from the data warehouse using the PullCatch.fn -#' @param strat.vars the variables used define the stratas. Defaul is bottom depth and latitudes. -#' @param strat.df the created strata matrix with the calculated areas by the createStrataDF.fn function -#' @param ageBins length bins -#' @param SSout if True the output is in a format pastable into SS dat file -#' @param meanRatioMethod TRUE/FALSE -#' @param sex sex value for Stock Synthesis -#' @param NAs2zero change NAs to zeros -#' @param sexRatioUnsexed sex ratio to apply to any length bins of a certain size or smaller as defined by the maxSizeUnsexed +#' Create expanded marginal age composition data based on the pre-specified strata. +#' This function is designed to be used with catch pulled using [pull_catch()] and +#' biological data pulled using [pull_bio()]. The default output is formatted based +#' on the formatting required by Stock Synthesis. +#' +#' @template dir +#' @param datA the biological data frame exctrated from the data warehouse using the [pull_bio()] +#' @param datTows the catch data frame extracted from the data warehouse using the [pull_catch()] +#' @template strat.vars +#' @template strat.df +#' @param ageBins Vector of age bins to create age compositions across. Values above or below the +#' minimum or maximum values, respectively, are grouped into the first age or plus group age. +#' @param SSout A logical with the default of `TRUE`. If `TRUE`, the output +#' is returned in a format that can be directly pasted into an SS3 data file. +#' @param meanRatioMethod A logical with the default of `TRUE`. If `TRUE`, then +#' the mean ratio is implemented instead of the total ratio. Search the +#' source code for the equations if more information is needed. +#' @template sex +#' @param NAs2zero A logical specifying if `NA`s should be changed to zeros. +#' The default is `TRUE`. +#' @param sexRatioUnsexed sex ratio to apply to any length bins of a certain size or smaller as defined +#' by the maxSizeUnsexed #' @param maxSizeUnsexed all sizes below this threshold will assign unsexed fish by sexRatio set equal to 0.50, fish larger than this size will have unsexed fish assigned by the calculated sex ratio in the data. #' @param sexRatioStage 1/2 apply the sex ratio based on the tows (1) or the expanded numbers (2) -#' @param partition partition for Stock Synthesis -#' @param fleet fleet number -#' @param agelow value for SS -1 -#' @param agehigh value for SS -1 -#' @param ageErr age error vector to apply -#' @param nSamps effective sample size for Stock Synthesis -#' @param month month when the samples were collected -#' @param printfolder folder where the length comps will be saved -#' @param remove999 the output object by the function will have the 999 column combined with the first length bin +#' @template partition +#' @template agelow +#' @template agehigh +#' @template ageEr +#' @param nSamps Vector of integer sample sizes. A vector of sample sizes for +#' all years in `datA` is required if a vector is provided. The input vector will be included in the +#' output marginal age composition data. One option for calculating input sample size is the [GetN.fn()]. +#' The default is "Enter Samps". +#' @template month +#' @template printfolder +#' @param remove999 The output object by the function will have the 999 column combined with the first age bin. +#' Default TRUE. #' @param outputStage1 return the first stage expanded data without compiling it for SS #' @template verbose #' @@ -37,10 +44,31 @@ #' @seealso \code{\link{SurveyLFs.fn}} -SurveyAFs.fn <- function(dir = NULL, datA, datTows, strat.vars = c("Depth_m", "Latitude_dd"), strat.df = NULL, ageBins = 1, SSout = TRUE, meanRatioMethod = TRUE, - sex = 3, NAs2zero = T, sexRatioUnsexed = NA, maxSizeUnsexed = NA, sexRatioStage = 1, partition = 0, fleet = "Enter Fleet", agelow = "Enter", - agehigh = "Enter", ageErr = "Enter", nSamps = "Enter Samps", month = "Enter Month", printfolder = "forSS", - remove999 = TRUE, outputStage1 = FALSE, verbose = TRUE) { +SurveyAFs.fn <- function( + dir = NULL, + datA, + datTows, + strat.vars = c("Depth_m", "Latitude_dd"), + strat.df = NULL, + ageBins = 1, + SSout = TRUE, + meanRatioMethod = TRUE, + sex = 3, + NAs2zero = T, + sexRatioUnsexed = NA, + maxSizeUnsexed = NA, + sexRatioStage = 1, + partition = 0, + fleet = "Enter Fleet", + agelow = "Enter", + agehigh = "Enter", + ageErr = "Enter", + nSamps = "Enter Samps", + month = "Enter Month", p + printfolder = "forSS", + remove999 = TRUE, + outputStage1 = FALSE, + verbose = TRUE) { # Overwrite inputs to use the same code for lengths as ages datL <- datA @@ -48,12 +76,29 @@ SurveyAFs.fn <- function(dir = NULL, datA, datTows, strat.vars = c("Depth_m", "L datL$Length_cm <- datA$Age out <- SurveyLFs.fn( - dir = dir, datL = datL, datTows = datTows, strat.vars = strat.vars, strat.df = strat.df, - lgthBins = lgthBins, SSout = SSout, meanRatioMethod = meanRatioMethod, - sex = sex, NAs2zero = NAs2zero, sexRatioUnsexed = sexRatioUnsexed, maxSizeUnsexed = maxSizeUnsexed, - sexRatioStage = sexRatioStage, partition = partition, fleet = fleet, nSamps = nSamps, - agelow = agelow, agehigh = agehigh, ageErr = ageErr, - month = month, printfolder = printfolder, remove999 = remove999, outputStage1 = outputStage1, + dir = dir, + datL = datL, + datTows = datTows, + strat.vars = strat.vars, + strat.df = strat.df, + lgthBins = lgthBins, + SSout = SSout, + meanRatioMethod = meanRatioMethod, + sex = sex, + NAs2zero = NAs2zero, + sexRatioUnsexed = sexRatioUnsexed, + maxSizeUnsexed = maxSizeUnsexed, + sexRatioStage = sexRatioStage, + partition = partition, + fleet = fleet, + nSamps = nSamps, + agelow = agelow, + agehigh = agehigh, + ageErr = ageErr, + month = month, + printfolder = printfolder, + remove999 = remove999, + outputStage1 = outputStage1, verbose = verbose ) return(out) diff --git a/R/SurveyAgeAtLen.fn.R b/R/SurveyAgeAtLen.fn.R index b4b3698..7d9a9d8 100644 --- a/R/SurveyAgeAtLen.fn.R +++ b/R/SurveyAgeAtLen.fn.R @@ -1,31 +1,36 @@ -#' Calculates proportion of age at length and reformats into SS format -#' Uses raw numbers at length, assuming that is a random sample conditioned on length and sex. -#' To use expanded numbers (up to strata areas), set raw=F -#' Only sex codes 1 and 2 and puts males and females on separate lines because the age@L is conditioned on sex (a sample of females of length 25cm, for example) -#' Gender=1: females only. Male values ignored -#' Gender=2: males only. Female values ignored. -#' lgthBins is either the interval between length bins or the actual length bins -#' note that 0 and Inf are tacked on the ends to account for lengths and ages outside the interval. You may want to add these in to first and last bin. -#' I assume all fish are sexed for age data, thus do not apply sex ratios for unsexed fish +#' Calculates conditional age-at-length composition data #' -#' @param dir directory this is where the output files will be saved -#' @param datAL the biological data frame exctrated from the data warehouse using the PullBio.fn -#' @param datTows the catch data frame extracted from the data warehouse using the PullCatch.fn -#' @param strat.vars the variables used define the stratas. Defaul is bottom depth and latitudes. -#' @param strat.df the created strata matrix with the calculated areas by the createStrataDF.fn function -#' @param lgthBins length bins -#' @param ageBins age bins -#' @param sex sex (0, 1, 2, 3) sex value for Stock Synthesis -#' @param SSout TRUE/FALSE return comps formatted for SS or in a raw form -#' @param meanRatioMethod TRUE/FALSE -#' @param raw TRUE/FALSE, input to define whether or not to expand numbers in the csv file (column header "NumF" and "NumM") -#' @param NAs2zero change NAs to zeros -#' @param month month -#' @param fleet fleet number -#' @param partition partition for Stock Synthesis -#' @param ageErr age error value for Stock Synthesis -#' @param returnSamps TRUE/FALSE stops the function after the sample size is calculated -#' @param printfolder folder where the length comps will be saved +#' Calculates conditional age-at-length composition data using raw numbers at length, +#' assuming that is a random sample conditioned on length and sex. +#' +#' +#' @template dir +#' @param datAL the biological data frame exctrated from the data warehouse using [pull_bio()] +#' @param datTows the catch data frame extracted from the data warehouse using [pull_catch()] +#' @template strat.vars +#' @template strat.df +#' @param lgthBins Vector of length bins to create length compositions across. Values above or below the +#' minimum or maximum values, respectively, are grouped into the first size or plus group size. +#' @param ageBins Vector of age bins to create age compositions across. Values above or below the +#' minimum or maximum values, respectively, are grouped into the first age or plus group age. +#' @template sex +#' @param SSout A logical with the default of `TRUE`. If `TRUE`, the output +#' is returned in a format that can be directly pasted into an SS3 data file. +#' @param meanRatioMethod A logical with the default of `TRUE`. If `TRUE`, then +#' the mean ratio is implemented instead of the total ratio. Search the +#' source code for the equations if more information is needed. +#' @param raw Logical input to define whether or not to expand numbers in the csv file with a default +# of `TRUE`. If `FALSE` a data frame will be returned with column header "NumF" and "NumM" with +#' unexpanded sample numbers. +#' @param NAs2zero A logical specifying if `NA`s should be changed to zeros. +#' The default is `TRUE`. +#' @template month +#' @template fleet +#' @template partition +#' @template ageErr +#' @param returnSamps A logical with the default of `FALSE`. A value of `TRUE` +#' stops the function after the sample size is calculated. +#' @template printfolder #' @template verbose #' #' @author Allan Hicks and Chantel Wetzel @@ -33,9 +38,26 @@ #' @seealso \code{\link{StrataFactors.fn}} #' @import reshape2 -SurveyAgeAtLen.fn <- function(dir = NULL, datAL, datTows, strat.vars = c("Depth_m", "Latitude_dd"), strat.df = NULL, lgthBins = 1, ageBins = 1, - sex = 3, SSout = TRUE, meanRatioMethod = TRUE, raw = TRUE, NAs2zero = TRUE, month = "Enter Month", fleet = "Enter Fleet", - partition = 0, ageErr = "Enter Age Error", returnSamps = FALSE, printfolder = "forSS", verbose = TRUE) { +SurveyAgeAtLen.fn <- function( + dir = NULL, + datAL, + datTows, + strat.vars = c("Depth_m", "Latitude_dd"), + strat.df = NULL, + lgthBins = 1, + ageBins = 1, + sex = 3, + SSout = TRUE, + meanRatioMethod = TRUE, + raw = TRUE, + NAs2zero = TRUE, + month = "Enter Month", + fleet = "Enter Fleet", + partition = 0, + ageErr = "Enter Age Error", + returnSamps = FALSE, + printfolder = "forSS", + verbose = TRUE) { plotdir <- file.path(dir, printfolder) check_dir(plotdir, verbose = verbose) diff --git a/R/SurveyLFs.fn.R b/R/SurveyLFs.fn.R index ef21685..1e272a4 100644 --- a/R/SurveyLFs.fn.R +++ b/R/SurveyLFs.fn.R @@ -1,52 +1,42 @@ -#' Expands the lengths up to the total stratum area then sums over strata +#' Expands the lengths up to the total stratum area then sums over strata for each year #' -#' @details -#' The original version was written by Allan Hicks 16 March 2009. This function -#' has since been modified by Chantel Wetzel to work with the data warehouse -#' data formatting, add additional options of when to apply the sex ratio, and -#' correct some treatment of unsexed fish weighted by sample size and area. +#' Create expanded length composition data based on the pre-specified strata. +#' This function is designed to be used with catch pulled using [pull_catch()] and +#' biological data pulled using [pull_bio()]. The default output is formatted based +#' on the formatting required by Stock Synthesis. #' -#' @param dir A file path to an existing directory where you would like to -#' create a folder to store the output from this function. The default is -#' `dir = NULL`, which causes the function to not save any files. You can -#' store the output directly in `dir` if you specify `printfolder = ""`. +#' @template dir #' @param datL A data frame of length-composition data returned from -#' [PullBio.fn()]. -#' @param datTows A data frame of catch data returned from [PullCatch.fn()]. -#' @param strat.vars Variables in both `datL` and `datTows` that are used to -#' define the stratas. Default is bottom depth (m) and latitudes (decimal -#' degrees), i.e., `c("Depth_m", "Latitude_dd")`. -#' @param strat.df A data frame that defines the strata and provides the -#' calculated areas for each strata returned from [createStrataDF.fn()]. -#' @param lgthBins An integer vector of length bins. +#' [pull_bio()]. +#' @param datTows A data frame of catch data returned from [pull_catch()]. +#' @template strat.vars +#' @template strat.df +#' @param lgthBins Vector of length bins to create length compositions across. Values above or below the +#' minimum or maximum values, respectively, are grouped into the first size or plus group size. #' @param SSout A logical with the default of `TRUE`. If `TRUE`, the output #' is returned in a format that can be directly pasted into an SS3 data file. #' @param meanRatioMethod A logical with the default of `TRUE`. If `TRUE`, then #' the mean ratio is implemented instead of the total ratio. Search the #' source code for the equations if more information is needed. -#' @param sex (0, 1, 2, 3). The integer will be used to define the sex column -#' of the returned input for Stock Synthesis and specifies how the -#' composition are treated with respect to sex. See the Stock Synthesis -#' manual for more information. In short, 0 is for unsexed, 1 is females, 2 -#' is males, and 3 is males and females where the sex ratio of the samples is -#' informative to the model. The default is `3`. +#' @template sex #' @param NAs2zero A logical specifying if `NA`s should be changed to zeros. #' The default is `TRUE`. #' @inheritParams SexRatio.fn #' @param sexRatioStage (1, 2). The stage of the expansion to apply the sex #' ratio. The default is `1`. -#' @param partition,fleet,agelow,agehigh,ageErr,month Each argument requires a -#' single integer value that will be used to set the associated column of the -#' returned input for Stock Synthesis. See the Stock Synthesis manual for -#' more information. -#' @param nSamps A named vector of input or effective sample sizes that will be -#' used to set the effective sample size of the returned input for Stock -#' Synthesis. A value must be supplied for every year of data in `datL`. -#' @param printfolder A string that will be appended to `dir`, creating a folder -#' where the length-composition output will be saved. If specified as `""`, -#' the output will just be saved directly in `dir`. The default is `"forSS"`. -#' @param remove999 A logical with the default of `TRUE`, which leads to the -#' output having the 999 column combined with the first length bin. +#' @template partition +#' @template agelow +#' @template agehigh +#' @template ageEr +#' @template fleet +#' @template month +#' @param nSamps Vector of integer sample sizes. A vector of sample sizes for +#' all years in `datL` is required if a vector is provided. The input vector will be included in the +#' output marginal age composition data. One option for calculating input sample size is the [GetN.fn()]. +#' The default is "Enter Samps". +#' @template printfolder +#' @param remove999 The output object by the function will have the 999 column combined with the first length bin. +#' Default TRUE. #' @param outputStage1 A logical specifying if you would like the function to #' stop after the end of the first stage of the expansion process and return #' output that is not ready for Stock Synthesis. This can be helpful when @@ -61,10 +51,31 @@ #' * [StrataFactors.fn()] #' * [SexRatio.fn()] -SurveyLFs.fn <- function(dir = NULL, datL, datTows, strat.vars = c("Depth_m", "Latitude_dd"), strat.df = NULL, lgthBins = 1, SSout = TRUE, meanRatioMethod = TRUE, - sex = 3, NAs2zero = T, sexRatioUnsexed = NA, maxSizeUnsexed = NA, sexRatioStage = 1, partition = 0, fleet = "Enter Fleet", - agelow = "Enter", agehigh = "Enter", ageErr = "Enter", nSamps = "Enter Samps", month = "Enter Month", printfolder = "forSS", - remove999 = TRUE, outputStage1 = FALSE, sum100 = TRUE, verbose = TRUE) { +SurveyLFs.fn <- function( + dir = NULL, datL, + datTows, + strat.vars = c("Depth_m", "Latitude_dd"), + strat.df = NULL, + lgthBins = 1, + SSout = TRUE, + meanRatioMethod = TRUE, + sex = 3, + NAs2zero = T, + sexRatioUnsexed = NA, + maxSizeUnsexed = NA, + sexRatioStage = 1, + partition = 0, + fleet = "Enter Fleet", + agelow = "Enter", + agehigh = "Enter", + ageErr = "Enter", + nSamps = "Enter Samps", + month = "Enter Month", + printfolder = "forSS", + remove999 = TRUE, + outputStage1 = FALSE, + sum100 = TRUE, + verbose = TRUE) { # Check for the number of tows were fish were observed but not measured postows <- datTows[which(datTows$total_catch_numbers > 0), ] diff --git a/R/UnexpandedAF.fn.R b/R/UnexpandedAF.fn.R index 152cd13..01cbb38 100644 --- a/R/UnexpandedAF.fn.R +++ b/R/UnexpandedAF.fn.R @@ -1,24 +1,36 @@ -#' Creates a matrix of length or age composition data WITHOUT expantion -#' Written by Chantel Wetzel to work with the data warehouse data formatting, +#' Creates a matrix of unexpanded age compositions #' -#' @param dir directory this is where the output files will be saved -#' @param datA the read in length comps by the PullBio.fn function -#' @param ageBins length bins -#' @param sex (0 = unsexed, 1 = females, 2 = males, 3 = females then males) sex value for Stock Synthesis -#' @param partition partition for Stock Synthesis -#' @param fleet fleet number -#' @param ageErr Number of ageing error matrix for SS -#' @param agelow age bin for SS (default value of -1) -#' @param agehigh age bin for SS (default value of -1) -#' @param month month the samples were collected -#' @param printfolder folder where the length comps will be saved +#' @template dir +#' @param datA A data frame of length-composition data returned from +#' [pull_bio()]. +#' @param ageBins Vector of age bins to create age compositions across. Values above or below the +#' minimum or maximum values, respectively, are grouped into the first age or plus group age. +#' @template ageErr +#' @template agelow +#' @template agehigh +#' @template sex +#' @template partition +#' @template fleet +#' @template month +#' @template printfolder #' @template verbose #' #' @author Chantel Wetzel #' @export -UnexpandedAFs.fn <- function(dir = NULL, datA, ageBins = 1, sex = 3, partition = 0, fleet = "Enter Fleet", - ageErr = "NA", agelow = -1, agehigh = -1, month = "Enter Month", printfolder = "forSS", verbose = TRUE) { +UnexpandedAFs.fn <- function( + dir = NULL, + datA, + ageBins = 1, + sex = 3, + partition = 0, + fleet = "Enter Fleet", + ageErr = "NA", + agelow = -1, + agehigh = -1, + month = "Enter Month", + printfolder = "forSS", + verbose = TRUE) { # Overwrite inputs to use the same code for lengths as ages datL <- datA diff --git a/R/checkStrata.fn.R b/R/checkStrata.fn.R index 7ba4bc2..990ecd2 100644 --- a/R/checkStrata.fn.R +++ b/R/checkStrata.fn.R @@ -1,24 +1,17 @@ -#' Calculates and returns the total number of tows and -#' positive tows conducted in each strata by year. The -#' selected stratas are used to expand the length and +#' Calculate the number of observations by year and strata +#' +#' Calculates and returns the total number of tows and +#' positive tows conducted in each strata by year. The +#' selected stratas are used to expand the length and #' marginal age compositions and to calculate a design -#' based index using the {Biomass.fn} function. +#' based index using the [Biomass.fn()]. #' -#' @param dir Directory where the output csv file will be -#' saved. -#' @param dat Data-frame of the catch data that has been -#' created by the {PullCatch.fn} function. -#' @param strat.vars A vector of the strata variable names. -#' The default input are c("Depth_m","Latitude_dd")) which -#' are the two factors the define a strata area off the coast. -#' @param strat.df Dataframe with the first column the name -#' of the stratum, the second column the area of the stratum, -#' and the remaining columns are the high and low variables -#' defining the strata created by the {CreateStrataDF.fn} function. -#' @param printfolder Folder name where files will be saved. The -#' default is "forSS" which is also used by other package functions -#' that creates and saves files that are commonly used or reported -#' in Stock Synthesis or the assessment document. +#' @template dir +#' @param dat Data-frame of the catch data that has been +#' created by [pull_catch()]. +#' @template strat.vars +#' @template strat.df +#' @template printfolder #' @template verbose #' #' @author Chantel Wetzel @@ -26,15 +19,15 @@ #' #' CheckStrata.fn <- function( - dir = NULL, - dat, - strat.vars = c("Depth_m", "Latitude_dd"), - strat.df, - printfolder = "forSS", + dir = NULL, + dat, + strat.vars = c("Depth_m", "Latitude_dd"), + strat.df, + printfolder = "forSS", verbose = TRUE) { # Grab the strata rownmaes to index later - row.names(strat.df) <- strat.df[, 1] + row.names(strat.df) <- strat.df[, 1] numStrata <- nrow(strat.df) # create strata factors diff --git a/R/createStrataDF.fn.R b/R/createStrataDF.fn.R index 4aeac90..385f21f 100644 --- a/R/createStrataDF.fn.R +++ b/R/createStrataDF.fn.R @@ -34,13 +34,19 @@ #' The data frame will have six columns, #' (1) name, (2) area, (3) Depth_m.1, (4) Depth_m.2, #' (5) Latitude_dd.1, and (6) Latitude_dd.2. +#' #' @author Chantel Wetzel and Kelli Johnson #' @export #' @seealso #' See \code{\link{StrataAreas.fn}} for how areas are calculated. -#' See \code{\link{Biomass.fn}} for how the areas are used to predict biomass. - -CreateStrataDF.fn <- function(names = NA, depths.shallow, depths.deep, lats.south, lats.north) { +#' See \code{\link{Biomass.fn}} for how the areas are used to create design-based biomass estimates. +#' +CreateStrataDF.fn <- function( + names = NA, + depths.shallow, + depths.deep, + lats.south, + lats.north) { SA3_v2021.1 <- NULL utils::data("SA3_v2021.1", envir = environment(), diff --git a/R/plotBio.fn.R b/R/plotBio.fn.R index 678b0f1..fbec07e 100644 --- a/R/plotBio.fn.R +++ b/R/plotBio.fn.R @@ -1,7 +1,7 @@ #' Plots the biomass with confidence intervals #' -#' @param dir directory to save the file -#' @param dat object created by the GetTotalBiomass.fn +#' @template dir +#' @param dat object created by the [Biomasss.fn()] #' @param CI confidence interval #' @param scalar simply the divisor for the biomass #' @param gap a value that introduces a slight gap between the point estimate and the start of the line for the CI. A gap too large will invert the CI, making it look huge. You should know when this happens @@ -20,8 +20,20 @@ #' @author Allan Hicks and John Wallace #' @export -PlotBio.fn <- function(dir = NULL, dat, CI = 0.95, scalar = 1e6, gap = 0.03, ylab = "Biomass ('000 mt)", xlab = "Year", - main = NULL, ylim = NULL, add = FALSE, col = "black", dopng = lifecycle::deprecated(), ...) { +PlotBio.fn <- function( + dir = NULL, + dat, + CI = 0.95, + scalar = 1e6, + gap = 0.03, + ylab = "Biomass ('000 mt)", + xlab = "Year", + main = NULL, + ylim = NULL, + add = FALSE, + col = "black", + dopng = lifecycle::deprecated(), + ...) { if (lifecycle::is_present(dopng)) { lifecycle::deprecate_warn( diff --git a/R/plotBioStrata.fn.R b/R/plotBioStrata.fn.R index 4ba3fc0..ed4ba35 100644 --- a/R/plotBioStrata.fn.R +++ b/R/plotBioStrata.fn.R @@ -1,7 +1,7 @@ -#' Plots the biomass with confidence intervals +#' Plots the design-based biomass estimates by strata with confidence intervals #' -#' @param dir directory to save the file -#' @param dat object created by the GetTotalBiomass.fn +#' @template dir +#' @param dat Data frame created by the [Biomass.fn()] #' @param CI confidence interval #' @param scalar simply the divisor for the biomass #' @param gap a value that introduces a slight gap between the point estimate and the start of the line for the CI. A gap too large will invert the CI, making it look huge. You should know when this happens @@ -13,7 +13,7 @@ #' @param mfrow.in option to specify the mfrow for plotting #' @param col color #' @param survey.name if specified will name the output png file using this name -#' @param strata.names custom strata names, if not specified will use the defined names from CreateStrataDF.fn +#' @param strata.names custom strata names, if not specified will use the defined names from [CreateStrataDF.fn()] #' @param pch.col Color as string, defaults to "black" #' @param pch.type Numeric pch type, defaults to 16 #' @param dopng Deprecated with {nwfscSurvey} 2.1 because providing a non-NULL @@ -25,9 +25,24 @@ #' @author Allan Hicks and John Wallace #' @export -PlotBioStrata.fn <- function(dir = NULL, dat, CI = 0.95, scalar = 1e6, gap = 0.03, ylab = "Biomass ('000 mt)", xlab = "Year", - survey.name = NULL, strata.names = NULL, ylim = NULL, sameylim = FALSE, add = FALSE, mfrow.in = NULL, col = "black", - pch.col = "black", pch.type = 16, dopng = lifecycle::deprecated(), ...) { +PlotBioStrata.fn <- function( + dir = NULL, dat, + CI = 0.95, + scalar = 1e6, + gap = 0.03, + ylab = "Biomass ('000 mt)", + xlab = "Year", + survey.name = NULL, + strata.names = NULL, + ylim = NULL, + sameylim = FALSE, + add = FALSE, + mfrow.in = NULL, + col = "black", + pch.col = "black", + pch.type = 16, + dopng = lifecycle::deprecated(), + ...) { if (lifecycle::is_present(dopng)) { lifecycle::deprecate_warn( diff --git a/R/plotFreqData.fn.R b/R/plotFreqData.fn.R index b860b36..0d662fc 100644 --- a/R/plotFreqData.fn.R +++ b/R/plotFreqData.fn.R @@ -1,13 +1,12 @@ -#' This function plots frequency data as bubble plots -#' You may want to change all zeros to NA's so that those observations are not plotted. -#' If you don't then set zero2NAs=F +#' Plot length or age compositions by year in bubble plots #' -#' @param dir directory to save files to -#' @param dat object created by SS3LF.fn or SS3AF.fn +#' @template dir +#' @param dat Object created by [SurveyLFs.fn()] or [SurveyAFs.fn()] #' @param inch input to the symbols plot: TRUE, FALSE or a positive number. #' @param ylab y-axis text label #' @param xlab x-axis text label -#' @param zero2NAs T/F change 0 values to NA +#' @param zero2NAs A logical specifying if `NA`s should be changed to zeros. +#' The default is `TRUE`. #' @param main main plot text #' @param xlim x-limit values #' @param ymax Value used to truncate y-axis, defaults to NULL @@ -22,8 +21,20 @@ #' @author Allan Hicks and Chantel Wetzel #' @export -PlotFreqData.fn <- function(dir = NULL, dat, inch = 0.15, ylab = "Bins", xlab = "Year", zero2NAs = T, main = NULL, - xlim = NULL, ymax = NULL, dopng = lifecycle::deprecated(), w = 7, h = 7, ...) { +PlotFreqData.fn <- function( + dir = NULL, + dat, + inch = 0.15, + ylab = "Bins", + xlab = "Year", + zero2NAs = TRUE, + main = NULL, + xlim = NULL, + ymax = NULL, + dopng = lifecycle::deprecated(), + w = 7, + h = 7, + ...) { if (lifecycle::is_present(dopng)) { lifecycle::deprecate_warn( diff --git a/R/plotVarLengthAtAge.fn.R b/R/plotVarLengthAtAge.fn.R index bf36832..57a817e 100644 --- a/R/plotVarLengthAtAge.fn.R +++ b/R/plotVarLengthAtAge.fn.R @@ -3,14 +3,15 @@ #' Plots the SD and CV of age at observed and predicted length #' #' -#' @param dir directory to save the file -#' @param dat The data loaded from the NWFSC database -#' @param main Name that will be used to name the saved png -#' @param ageBin Currently fixed at 1, so a moot parameter -#' @param bySex Logical to indicate if plot by sex +#' @template dir +#' @param dat A data frame of length-composition data returned from +#' [pull_bio()]. +#' @param main Name that will be used to name the saved png +#' @param ageBin Currently fixed at 1, so a moot parameter +#' @param bySex Logical to indicate if plot by sex #' @param parStart Vector of starting parameters for Linf, k, and t0 in VonB estimation -#' @param estVB Logical. Estimate vonB growth to plot against predicted length. If F, it uses the paramters in \code{parStart}. -#' @param bins The bins to put ages into. If NULL then simply uses the ages as recorded. +#' @param estVB Logical. Estimate vonB growth to plot against predicted length. If F, it uses the paramters in \code{parStart}. +#' @param bins The bins to put ages into. If NULL then simply uses the ages as recorded. #' @param legX legend location for x axis, defaults to "bottomleft" #' @param legY legend location for y axis, defaults to NULL #' @param dopng Deprecated with {nwfscSurvey} 2.1 because providing a non-NULL @@ -22,7 +23,19 @@ #' @author Allan Hicks and Chantel Wetzel #' @export -PlotVarLengthAtAge.fn <- function(dir = NULL, dat, main = NULL, ageBin = 1, bySex = T, parStart = c(52, 0.09, 1), estVB = T, bins = NULL, legX = "bottomleft", legY = NULL, dopng = lifecycle::deprecated(), ...) { +PlotVarLengthAtAge.fn <- function( + dir = NULL, + dat, + main = NULL, + ageBin = 1, + bySex = T, + parStart = c(52, 0.09, 1), + estVB = T, + bins = NULL, + legX = "bottomleft", + legY = NULL, + dopng = lifecycle::deprecated(), + ...) { if (lifecycle::is_present(dopng)) { lifecycle::deprecate_warn( diff --git a/R/unexpandedLF.fn.R b/R/unexpandedLF.fn.R index 14cc119..5c66fde 100644 --- a/R/unexpandedLF.fn.R +++ b/R/unexpandedLF.fn.R @@ -1,24 +1,37 @@ -#' Creates a matrix of length or age composition data WITHOUT expantion -#' Written by Chantel Wetzel to work with the data warehouse data formatting, +#' Creates a matrix of unexpanded length composition data #' -#' @param dir directory this is where the output files will be saved -#' @param datL the read in length comps by the PullBio.fn function -#' @param lgthBins length bins -#' @param ageErr Number of ageing error matrix for SS -#' @param agelow age bin for SS (default value of -1) -#' @param agehigh age bin for SS (default value of -1) -#' @param sex (0 = unsexed, 1 = females, 2 = males, 3 = females then males) sex value for Stock Synthesis -#' @param partition partition for Stock Synthesis -#' @param fleet fleet number -#' @param month month the samples were collected -#' @param printfolder folder where the length comps will be saved +#' +#' @template dir +#' @param datL A data frame of length-composition data returned from +#' [pull_bio()]. +#' @param lgthBins Vector of length bins to create length compositions across. Values above or below the +#' minimum or maximum values, respectively, are grouped into the first size or plus group size. +#' @template ageErr +#' @template agelow +#' @template agehigh +#' @template sex +#' @template partition +#' @template fleet +#' @template month +#' @template printfolder #' @template verbose #' #' @author Chantel Wetzel #' @export -UnexpandedLFs.fn <- function(dir = NULL, datL, lgthBins = 1, sex = 3, partition = 0, fleet = "Enter Fleet", - ageErr = "NA", agelow = -1, agehigh = -1, month = "Enter Month", printfolder = "forSS", verbose = TRUE) { +UnexpandedLFs.fn <- function( + dir = NULL, datL, + lgthBins = 1, + sex = 3, + partition = 0, + fleet = "Enter Fleet", + ageErr = "NA", + agelow = -1, + agehigh = -1, + month = "Enter Month", + printfolder = "forSS", + verbose = TRUE) { + plotdir <- file.path(dir, printfolder) check_dir(dir = plotdir, verbose = verbose) From f0c7115b9de7ee7b0a079dd1d9bc31ffadf51159 Mon Sep 17 00:00:00 2001 From: Chantel Wetzel Date: Wed, 8 May 2024 07:08:04 -0700 Subject: [PATCH 3/6] doc --- R/SurveyAFs.fn.R | 4 +- R/SurveyLFs.fn.R | 2 +- man/Biomass.fn.Rd | 48 ++++++++++-------- man/CheckStrata.fn.Rd | 33 +++++------- man/CreateStrataDF.fn.Rd | 2 +- man/Format.AKSlope.fn.Rd | 2 +- man/GetN.fn.Rd | 16 +++--- man/PlotBio.fn.Rd | 5 +- man/PlotBioStrata.fn.Rd | 11 ++-- man/PlotFreqData.fn.Rd | 18 +++---- man/PlotMap.fn.Rd | 4 +- man/PlotPresenceAbsence.fn.Rd | 2 +- man/PlotSexRatioStrata.fn.Rd | 13 +++-- man/PlotVarLengthAtAge.fn.Rd | 6 ++- man/SurveyAFs.fn.Rd | 92 ++++++++++++++++++++-------------- man/SurveyAgeAtLen.fn.Rd | 85 ++++++++++++++++++------------- man/SurveyLFs.fn.Rd | 76 +++++++++++++++++----------- man/UnexpandedAFs.fn.Rd | 50 ++++++++++++------ man/UnexpandedLFs.fn.Rd | 50 ++++++++++++------ man/check_dir.Rd | 2 +- man/pull_bio.Rd | 2 +- man/pull_biological_samples.Rd | 2 +- man/pull_catch.Rd | 2 +- man/pull_gemm.Rd | 2 +- man/pull_haul.Rd | 2 +- man/save_rdata.Rd | 2 +- 26 files changed, 312 insertions(+), 221 deletions(-) diff --git a/R/SurveyAFs.fn.R b/R/SurveyAFs.fn.R index caee10a..6fcd4c8 100644 --- a/R/SurveyAFs.fn.R +++ b/R/SurveyAFs.fn.R @@ -27,7 +27,7 @@ #' @template partition #' @template agelow #' @template agehigh -#' @template ageEr +#' @template ageErr #' @param nSamps Vector of integer sample sizes. A vector of sample sizes for #' all years in `datA` is required if a vector is provided. The input vector will be included in the #' output marginal age composition data. One option for calculating input sample size is the [GetN.fn()]. @@ -64,7 +64,7 @@ SurveyAFs.fn <- function( agehigh = "Enter", ageErr = "Enter", nSamps = "Enter Samps", - month = "Enter Month", p + month = "Enter Month", printfolder = "forSS", remove999 = TRUE, outputStage1 = FALSE, diff --git a/R/SurveyLFs.fn.R b/R/SurveyLFs.fn.R index 1e272a4..380b1e8 100644 --- a/R/SurveyLFs.fn.R +++ b/R/SurveyLFs.fn.R @@ -27,7 +27,7 @@ #' @template partition #' @template agelow #' @template agehigh -#' @template ageEr +#' @template ageErr #' @template fleet #' @template month #' @param nSamps Vector of integer sample sizes. A vector of sample sizes for diff --git a/man/Biomass.fn.Rd b/man/Biomass.fn.Rd index d4cde07..26e1447 100644 --- a/man/Biomass.fn.Rd +++ b/man/Biomass.fn.Rd @@ -2,11 +2,7 @@ % Please edit documentation in R/Biomass.fn.R \name{Biomass.fn} \alias{Biomass.fn} -\title{Calculates design based estimates from survey data for West Coast surveys. -The design based index is calculated based on the area of the strata and -the mean catch by strata. -See: Gunderson, D.R. and Sample, T.M. 1980. Distribution and abundance of rockfish off Washington, -Oregon, and California during 1977. Marine Fisheries Review: March - April.} +\title{Calculates design based estimates from survey data for West Coast surveys.} \usage{ Biomass.fn( dir = NULL, @@ -15,25 +11,34 @@ Biomass.fn( strat.df, printfolder = "forSS", outputMedian = TRUE, - month = NA, - fleet = NA, + month = "Enter month", + fleet = "Enter fleet", verbose = TRUE ) } \arguments{ -\item{dir}{directory where the output file will be saved} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{data-frame of the data that has been by the PullCatch.fn} +\item{dat}{Data frame of catch data that has been created by the \code{\link[=pull_catch]{pull_catch()}}.} -\item{strat.vars}{A vector of the strata variable names (i.e., c("Depth_m","Latitude_dd"))} +\item{strat.vars}{Variables in both data frame that are used to +define the stratas. Default is bottom depth (m) and latitudes (decimal +degrees), i.e., \code{c("Depth_m", "Latitude_dd")}.} -\item{strat.df}{a dataframe with the first column the name of the stratum, the second column the area of the stratum, and the remaining columns are the high and low variables defining the strata created by the CreateStrataDF.fn} +\item{strat.df}{A data frame that defines the strata and provides the +calculated areas for each strata returned from \code{\link[=createStrataDF.fn]{createStrataDF.fn()}}.} -\item{printfolder}{the folder where files will be saved} +\item{printfolder}{A string that will be appended to \code{dir}, creating a folder +where the output will be saved. If specified as \code{""}, +the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} -\item{outputMedian}{T/F output median or the mean biomass estimate} +\item{outputMedian}{Specify whether to output median or the mean biomass estimate. Default \code{TRUE}.} -\item{month}{month for SS} +\item{month}{A single integer value between 1-12. A user input fleet +number to assign to the month column based on the expected +format for Stock Synthesis. See the Stock Synthesis manual for +more information. Default "Enter Month".} \item{fleet}{fleet number for SS} @@ -41,14 +46,13 @@ Biomass.fn( warnings to the console. The default is \code{TRUE}.} } \description{ -The variables defining the strata must begin with the name in strat.vars and end with ".1" or ".2" (i.e., Depth_m.1) -the strata are assumed to be continuous variables, thus have a lower and upper value defining them. The lower value does not necessarily have to be the same as the previous upper value. -the stat.df dataframe is difficult to build up with more than one variable becuase it turns into a design where you have to define all areas, thus repeat the variables for one (like a design) -} -\details{ -I calculate the variance given stratified sampling theory -I work in normal space, then calculate the statistics if B is lognormal -This is the Mean Ratio Estimate +The design based index is calculated based on the area of the strata and +the mean catch by strata. This function returns a list of design-based +estimates by strata and estimates combined across stratas by year. This +function is designed to work with data frames pulled from the NWFSC +data warehouse using \code{\link[=pull_catch]{pull_catch()}}. +See: Gunderson, D.R. and Sample, T.M. 1980. Distribution and abundance of rockfish off Washington, +Oregon, and California during 1977. Marine Fisheries Review: March - April. } \author{ Allan Hicks and Chantel Wetzel diff --git a/man/CheckStrata.fn.Rd b/man/CheckStrata.fn.Rd index f43cf9e..512a0f7 100644 --- a/man/CheckStrata.fn.Rd +++ b/man/CheckStrata.fn.Rd @@ -2,11 +2,7 @@ % Please edit documentation in R/checkStrata.fn.R \name{CheckStrata.fn} \alias{CheckStrata.fn} -\title{Calculates and returns the total number of tows and -positive tows conducted in each strata by year. The -selected stratas are used to expand the length and -marginal age compositions and to calculate a design -based index using the {Biomass.fn} function.} +\title{Calculate the number of observations by year and strata} \usage{ CheckStrata.fn( dir = NULL, @@ -18,25 +14,22 @@ CheckStrata.fn( ) } \arguments{ -\item{dir}{Directory where the output csv file will be -saved.} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} \item{dat}{Data-frame of the catch data that has been -created by the {PullCatch.fn} function.} +created by \code{\link[=pull_catch]{pull_catch()}}.} -\item{strat.vars}{A vector of the strata variable names. -The default input are c("Depth_m","Latitude_dd")) which -are the two factors the define a strata area off the coast.} +\item{strat.vars}{Variables in both data frame that are used to +define the stratas. Default is bottom depth (m) and latitudes (decimal +degrees), i.e., \code{c("Depth_m", "Latitude_dd")}.} -\item{strat.df}{Dataframe with the first column the name -of the stratum, the second column the area of the stratum, -and the remaining columns are the high and low variables -defining the strata created by the {CreateStrataDF.fn} function.} +\item{strat.df}{A data frame that defines the strata and provides the +calculated areas for each strata returned from \code{\link[=createStrataDF.fn]{createStrataDF.fn()}}.} -\item{printfolder}{Folder name where files will be saved. The -default is "forSS" which is also used by other package functions -that creates and saves files that are commonly used or reported -in Stock Synthesis or the assessment document.} +\item{printfolder}{A string that will be appended to \code{dir}, creating a folder +where the output will be saved. If specified as \code{""}, +the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} \item{verbose}{A logical that specifies if you want to print messages and warnings to the console. The default is \code{TRUE}.} @@ -46,7 +39,7 @@ Calculates and returns the total number of tows and positive tows conducted in each strata by year. The selected stratas are used to expand the length and marginal age compositions and to calculate a design -based index using the {Biomass.fn} function. +based index using the \code{\link[=Biomass.fn]{Biomass.fn()}}. } \author{ Chantel Wetzel diff --git a/man/CreateStrataDF.fn.Rd b/man/CreateStrataDF.fn.Rd index a1fea63..2a4658d 100644 --- a/man/CreateStrataDF.fn.Rd +++ b/man/CreateStrataDF.fn.Rd @@ -57,7 +57,7 @@ strata <- CreateStrataDF.fn( } \seealso{ See \code{\link{StrataAreas.fn}} for how areas are calculated. -See \code{\link{Biomass.fn}} for how the areas are used to predict biomass. +See \code{\link{Biomass.fn}} for how the areas are used to create design-based biomass estimates. } \author{ Chantel Wetzel and Kelli Johnson diff --git a/man/Format.AKSlope.fn.Rd b/man/Format.AKSlope.fn.Rd index 14e5573..7432e0f 100644 --- a/man/Format.AKSlope.fn.Rd +++ b/man/Format.AKSlope.fn.Rd @@ -18,7 +18,7 @@ Format.AKSlope.fn( ) } \arguments{ -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} \item{datTows}{A data frame of catch data for the diff --git a/man/GetN.fn.Rd b/man/GetN.fn.Rd index 507fd8f..5ca1f76 100644 --- a/man/GetN.fn.Rd +++ b/man/GetN.fn.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/GetN.fn.R \name{GetN.fn} \alias{GetN.fn} -\title{Calculate effN input sample sizes} +\title{Calculate input sample sizes} \usage{ GetN.fn( dir = NULL, @@ -15,11 +15,10 @@ GetN.fn( ) } \arguments{ -\item{dir}{A file path to the main directory where -\code{printfolder} will be created. If \code{NULL}, which is the default, -then no files will be written to the disk.} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{A \code{data.frame} of composition data.} +\item{dat}{A \code{data.frame} of composition data created using \code{\link[=pull_bio]{pull_bio()}}.} \item{type}{A string specifying whether doing "length" or "age" that is used to ensure the sample size is of the correct column and create @@ -30,8 +29,9 @@ will lead to the use of the correct species-specific value for the number of unique samples per tow. See the function call for allowed values, where the default is \code{"all"}.} -\item{printfolder}{A string that will be used to create the name of the -folder where files will be saved, i.e., \code{file.path(dir, printfolder)}.} +\item{printfolder}{A string that will be appended to \code{dir}, creating a folder +where the output will be saved. If specified as \code{""}, +the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} \item{output}{A string, where the default is \code{NULL}, which returns only a vector of samples sizes. @@ -42,7 +42,7 @@ a table of observations by year and sex.} warnings to the console. The default is \code{TRUE}.} } \description{ -Calculate effN input sample sizes +Calculate input sample sizes } \references{ Stewart, I.J. and O.S. Hamel. 2014. diff --git a/man/PlotBio.fn.Rd b/man/PlotBio.fn.Rd index 020c5bf..add4138 100644 --- a/man/PlotBio.fn.Rd +++ b/man/PlotBio.fn.Rd @@ -21,9 +21,10 @@ PlotBio.fn( ) } \arguments{ -\item{dir}{directory to save the file} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{object created by the GetTotalBiomass.fn} +\item{dat}{object created by the \code{\link[=Biomasss.fn]{Biomasss.fn()}}} \item{CI}{confidence interval} diff --git a/man/PlotBioStrata.fn.Rd b/man/PlotBioStrata.fn.Rd index a49f35b..ebc749a 100644 --- a/man/PlotBioStrata.fn.Rd +++ b/man/PlotBioStrata.fn.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/plotBioStrata.fn.R \name{PlotBioStrata.fn} \alias{PlotBioStrata.fn} -\title{Plots the biomass with confidence intervals} +\title{Plots the design-based biomass estimates by strata with confidence intervals} \usage{ PlotBioStrata.fn( dir = NULL, @@ -26,9 +26,10 @@ PlotBioStrata.fn( ) } \arguments{ -\item{dir}{directory to save the file} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{object created by the GetTotalBiomass.fn} +\item{dat}{Data frame created by the \code{\link[=Biomass.fn]{Biomass.fn()}}} \item{CI}{confidence interval} @@ -42,7 +43,7 @@ PlotBioStrata.fn( \item{survey.name}{if specified will name the output png file using this name} -\item{strata.names}{custom strata names, if not specified will use the defined names from CreateStrataDF.fn} +\item{strata.names}{custom strata names, if not specified will use the defined names from \code{\link[=CreateStrataDF.fn]{CreateStrataDF.fn()}}} \item{ylim}{y-limits} @@ -66,7 +67,7 @@ no longer have to specify \code{dopng} to save the plot as a png.} \item{...}{Additional arguments for the plots} } \description{ -Plots the biomass with confidence intervals +Plots the design-based biomass estimates by strata with confidence intervals } \author{ Allan Hicks and John Wallace diff --git a/man/PlotFreqData.fn.Rd b/man/PlotFreqData.fn.Rd index 7be7119..6ab309d 100644 --- a/man/PlotFreqData.fn.Rd +++ b/man/PlotFreqData.fn.Rd @@ -2,9 +2,7 @@ % Please edit documentation in R/plotFreqData.fn.R \name{PlotFreqData.fn} \alias{PlotFreqData.fn} -\title{This function plots frequency data as bubble plots -You may want to change all zeros to NA's so that those observations are not plotted. -If you don't then set zero2NAs=F} +\title{Plot length or age compositions by year in bubble plots} \usage{ PlotFreqData.fn( dir = NULL, @@ -12,7 +10,7 @@ PlotFreqData.fn( inch = 0.15, ylab = "Bins", xlab = "Year", - zero2NAs = T, + zero2NAs = TRUE, main = NULL, xlim = NULL, ymax = NULL, @@ -23,9 +21,10 @@ PlotFreqData.fn( ) } \arguments{ -\item{dir}{directory to save files to} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{object created by SS3LF.fn or SS3AF.fn} +\item{dat}{Object created by \code{\link[=SurveyLFs.fn]{SurveyLFs.fn()}} or \code{\link[=SurveyAFs.fn]{SurveyAFs.fn()}}} \item{inch}{input to the symbols plot: TRUE, FALSE or a positive number.} @@ -33,7 +32,8 @@ PlotFreqData.fn( \item{xlab}{x-axis text label} -\item{zero2NAs}{T/F change 0 values to NA} +\item{zero2NAs}{A logical specifying if \code{NA}s should be changed to zeros. +The default is \code{TRUE}.} \item{main}{main plot text} @@ -53,9 +53,7 @@ no longer have to specify \code{dopng} to save the plot as a png.} \item{...}{Additional arguments for the plots} } \description{ -This function plots frequency data as bubble plots -You may want to change all zeros to NA's so that those observations are not plotted. -If you don't then set zero2NAs=F +Plot length or age compositions by year in bubble plots } \author{ Allan Hicks and Chantel Wetzel diff --git a/man/PlotMap.fn.Rd b/man/PlotMap.fn.Rd index 801155b..2982499 100644 --- a/man/PlotMap.fn.Rd +++ b/man/PlotMap.fn.Rd @@ -13,10 +13,10 @@ PlotMap.fn( ) } \arguments{ -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} -\item{dat}{An object created by \code{\link[=PullCatch.fn]{PullCatch.fn()}}.} +\item{dat}{An object created by \code{\link[=pull_catch]{pull_catch()}}.} \item{main}{A string that will be prepended to the name of the saved png (i.e., "NWFSC" results in a file called "NWFSC_CPUE_Map.png").} diff --git a/man/PlotPresenceAbsence.fn.Rd b/man/PlotPresenceAbsence.fn.Rd index 2a15238..ed78b94 100644 --- a/man/PlotPresenceAbsence.fn.Rd +++ b/man/PlotPresenceAbsence.fn.Rd @@ -27,7 +27,7 @@ be true for the latter.} \item{dim}{Dimension of interest, either "depth", "lat", or "sex".} -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} \item{dopng}{Deprecated with {nwfscSurvey} 2.1 because providing a non-NULL diff --git a/man/PlotSexRatioStrata.fn.Rd b/man/PlotSexRatioStrata.fn.Rd index e06197b..f8a0d4d 100644 --- a/man/PlotSexRatioStrata.fn.Rd +++ b/man/PlotSexRatioStrata.fn.Rd @@ -16,15 +16,20 @@ PlotSexRatioStrata.fn( ) } \arguments{ -\item{dir}{directory location for saving the png} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{data object} +\item{dat}{A data frame of length-composition data returned from +\code{\link[=pull_bio]{pull_bio()}}.} \item{type}{length/age which data type to use} -\item{strat.vars}{the parameters to stratify the data} +\item{strat.vars}{Variables in both data frame that are used to +define the stratas. Default is bottom depth (m) and latitudes (decimal +degrees), i.e., \code{c("Depth_m", "Latitude_dd")}.} -\item{strat.df}{the created strata matrix with the calculated areas by the createStrataDF.fn function} +\item{strat.df}{A data frame that defines the strata and provides the +calculated areas for each strata returned from \code{\link[=createStrataDF.fn]{createStrataDF.fn()}}.} \item{circleSize}{circle size} diff --git a/man/PlotVarLengthAtAge.fn.Rd b/man/PlotVarLengthAtAge.fn.Rd index 8ab8ef7..c9448b0 100644 --- a/man/PlotVarLengthAtAge.fn.Rd +++ b/man/PlotVarLengthAtAge.fn.Rd @@ -20,9 +20,11 @@ PlotVarLengthAtAge.fn( ) } \arguments{ -\item{dir}{directory to save the file} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{The data loaded from the NWFSC database} +\item{dat}{A data frame of length-composition data returned from +\code{\link[=pull_bio]{pull_bio()}}.} \item{main}{Name that will be used to name the saved png} diff --git a/man/SurveyAFs.fn.Rd b/man/SurveyAFs.fn.Rd index 1e1ec46..2d30745 100644 --- a/man/SurveyAFs.fn.Rd +++ b/man/SurveyAFs.fn.Rd @@ -2,14 +2,7 @@ % Please edit documentation in R/SurveyAFs.fn.R \name{SurveyAFs.fn} \alias{SurveyAFs.fn} -\title{Expands the ages up to the total stratum area then sums over strata -Original Version Written by Allan Hicks 16 March 2009 -Modified by Chantel Wetzel to work with the data warehouse data formatting, -add additional options of when to apply the sex ratio, and correct some treatment of unsexed fish -weighted by sample size and area -NOTE: The age bin called F0 or M0 is retained to show proportion of ages smaller than smallest bin -You will want to likely add this to your first age bin and delete this before putting in SS, or -start the ageBins argument at the 2nd age bin and F0 will be all fish smaller (hence the first age bin)} +\title{Create marginal age composition data} \usage{ SurveyAFs.fn( dir = NULL, @@ -39,49 +32,78 @@ SurveyAFs.fn( ) } \arguments{ -\item{dir}{directory this is where the output files will be saved} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{datA}{the biological data frame exctrated from the data warehouse using the PullBio.fn} +\item{datA}{the biological data frame exctrated from the data warehouse using the \code{\link[=pull_bio]{pull_bio()}}} -\item{datTows}{the catch data frame extracted from the data warehouse using the PullCatch.fn} +\item{datTows}{the catch data frame extracted from the data warehouse using the \code{\link[=pull_catch]{pull_catch()}}} -\item{strat.vars}{the variables used define the stratas. Defaul is bottom depth and latitudes.} +\item{strat.vars}{Variables in both data frame that are used to +define the stratas. Default is bottom depth (m) and latitudes (decimal +degrees), i.e., \code{c("Depth_m", "Latitude_dd")}.} -\item{strat.df}{the created strata matrix with the calculated areas by the createStrataDF.fn function} +\item{strat.df}{A data frame that defines the strata and provides the +calculated areas for each strata returned from \code{\link[=createStrataDF.fn]{createStrataDF.fn()}}.} -\item{ageBins}{length bins} +\item{ageBins}{Vector of age bins to create age compositions across. Values above or below the +minimum or maximum values, respectively, are grouped into the first age or plus group age.} -\item{SSout}{if True the output is in a format pastable into SS dat file} +\item{SSout}{A logical with the default of \code{TRUE}. If \code{TRUE}, the output +is returned in a format that can be directly pasted into an SS3 data file.} -\item{meanRatioMethod}{TRUE/FALSE} +\item{meanRatioMethod}{A logical with the default of \code{TRUE}. If \code{TRUE}, then +the mean ratio is implemented instead of the total ratio. Search the +source code for the equations if more information is needed.} -\item{sex}{sex value for Stock Synthesis} +\item{sex}{Options of (0, 1, 2, 3). The integer will be used to define the sex column +of the returned input for Stock Synthesis and specifies how the +composition are treated with respect to sex. See the Stock Synthesis +manual for more information. In short, 0 is for unsexed, 1 is females, 2 +is males, and 3 is females and males. The default is \code{3}.} -\item{NAs2zero}{change NAs to zeros} +\item{NAs2zero}{A logical specifying if \code{NA}s should be changed to zeros. +The default is \code{TRUE}.} -\item{sexRatioUnsexed}{sex ratio to apply to any length bins of a certain size or smaller as defined by the maxSizeUnsexed} +\item{sexRatioUnsexed}{sex ratio to apply to any length bins of a certain size or smaller as defined +by the maxSizeUnsexed} \item{maxSizeUnsexed}{all sizes below this threshold will assign unsexed fish by sexRatio set equal to 0.50, fish larger than this size will have unsexed fish assigned by the calculated sex ratio in the data.} \item{sexRatioStage}{1/2 apply the sex ratio based on the tows (1) or the expanded numbers (2)} -\item{partition}{partition for Stock Synthesis} +\item{partition}{Partition to assign the composition data based on the expected +format for Stock Synthesis. Partition of 0 indicates that the composition data +include all composition data, 1 for discarded composition data, and 2 for retained +fish only. Default of 0.} -\item{fleet}{fleet number} +\item{agelow}{Lower age bin for all age composition data based on the expected +format for Stock Synthesis. Default value of -1 which translates to the lowest age +bin.} -\item{agelow}{value for SS -1} +\item{agehigh}{Upper age bin for all age composition data based on the expected +format for Stock Synthesis. Default value of -1 which translates to the highest} -\item{agehigh}{value for SS -1} +\item{ageErr}{Single interget value of ageing error +vector to apply to the age data based on +Stock Synthesis. Default "Enter".} -\item{ageErr}{age error vector to apply} +\item{nSamps}{Vector of integer sample sizes. A vector of sample sizes for +all years in \code{datA} is required if a vector is provided. The input vector will be included in the +output marginal age composition data. One option for calculating input sample size is the \code{\link[=GetN.fn]{GetN.fn()}}. +The default is "Enter Samps".} -\item{nSamps}{effective sample size for Stock Synthesis} +\item{month}{A single integer value between 1-12. A user input fleet +number to assign to the month column based on the expected +format for Stock Synthesis. See the Stock Synthesis manual for +more information. Default "Enter Month".} -\item{month}{month when the samples were collected} +\item{printfolder}{A string that will be appended to \code{dir}, creating a folder +where the output will be saved. If specified as \code{""}, +the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} -\item{printfolder}{folder where the length comps will be saved} - -\item{remove999}{the output object by the function will have the 999 column combined with the first length bin} +\item{remove999}{The output object by the function will have the 999 column combined with the first age bin. +Default TRUE.} \item{outputStage1}{return the first stage expanded data without compiling it for SS} @@ -89,14 +111,10 @@ SurveyAFs.fn( warnings to the console. The default is \code{TRUE}.} } \description{ -Expands the ages up to the total stratum area then sums over strata -Original Version Written by Allan Hicks 16 March 2009 -Modified by Chantel Wetzel to work with the data warehouse data formatting, -add additional options of when to apply the sex ratio, and correct some treatment of unsexed fish -weighted by sample size and area -NOTE: The age bin called F0 or M0 is retained to show proportion of ages smaller than smallest bin -You will want to likely add this to your first age bin and delete this before putting in SS, or -start the ageBins argument at the 2nd age bin and F0 will be all fish smaller (hence the first age bin) +Create expanded marginal age composition data based on the pre-specified strata. +This function is designed to be used with catch pulled using \code{\link[=pull_catch]{pull_catch()}} and +biological data pulled using \code{\link[=pull_bio]{pull_bio()}}. The default output is formatted based +on the formatting required by Stock Synthesis. } \seealso{ \code{\link{SurveyLFs.fn}} diff --git a/man/SurveyAgeAtLen.fn.Rd b/man/SurveyAgeAtLen.fn.Rd index 065ee58..8251694 100644 --- a/man/SurveyAgeAtLen.fn.Rd +++ b/man/SurveyAgeAtLen.fn.Rd @@ -2,15 +2,7 @@ % Please edit documentation in R/SurveyAgeAtLen.fn.R \name{SurveyAgeAtLen.fn} \alias{SurveyAgeAtLen.fn} -\title{Calculates proportion of age at length and reformats into SS format -Uses raw numbers at length, assuming that is a random sample conditioned on length and sex. -To use expanded numbers (up to strata areas), set raw=F -Only sex codes 1 and 2 and puts males and females on separate lines because the age@L is conditioned on sex (a sample of females of length 25cm, for example) -Gender=1: females only. Male values ignored -Gender=2: males only. Female values ignored. -lgthBins is either the interval between length bins or the actual length bins -note that 0 and Inf are tacked on the ends to account for lengths and ages outside the interval. You may want to add these in to first and last bin. -I assume all fish are sexed for age data, thus do not apply sex ratios for unsexed fish} +\title{Calculates conditional age-at-length composition data} \usage{ SurveyAgeAtLen.fn( dir = NULL, @@ -35,55 +27,76 @@ SurveyAgeAtLen.fn( ) } \arguments{ -\item{dir}{directory this is where the output files will be saved} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{datAL}{the biological data frame exctrated from the data warehouse using the PullBio.fn} +\item{datAL}{the biological data frame exctrated from the data warehouse using \code{\link[=pull_bio]{pull_bio()}}} -\item{datTows}{the catch data frame extracted from the data warehouse using the PullCatch.fn} +\item{datTows}{the catch data frame extracted from the data warehouse using \code{\link[=pull_catch]{pull_catch()}}} -\item{strat.vars}{the variables used define the stratas. Defaul is bottom depth and latitudes.} +\item{strat.vars}{Variables in both data frame that are used to +define the stratas. Default is bottom depth (m) and latitudes (decimal +degrees), i.e., \code{c("Depth_m", "Latitude_dd")}.} -\item{strat.df}{the created strata matrix with the calculated areas by the createStrataDF.fn function} +\item{strat.df}{A data frame that defines the strata and provides the +calculated areas for each strata returned from \code{\link[=createStrataDF.fn]{createStrataDF.fn()}}.} -\item{lgthBins}{length bins} +\item{lgthBins}{Vector of length bins to create length compositions across. Values above or below the +minimum or maximum values, respectively, are grouped into the first size or plus group size.} -\item{ageBins}{age bins} +\item{ageBins}{Vector of age bins to create age compositions across. Values above or below the +minimum or maximum values, respectively, are grouped into the first age or plus group age.} -\item{sex}{sex (0, 1, 2, 3) sex value for Stock Synthesis} +\item{sex}{Options of (0, 1, 2, 3). The integer will be used to define the sex column +of the returned input for Stock Synthesis and specifies how the +composition are treated with respect to sex. See the Stock Synthesis +manual for more information. In short, 0 is for unsexed, 1 is females, 2 +is males, and 3 is females and males. The default is \code{3}.} -\item{SSout}{TRUE/FALSE return comps formatted for SS or in a raw form} +\item{SSout}{A logical with the default of \code{TRUE}. If \code{TRUE}, the output +is returned in a format that can be directly pasted into an SS3 data file.} -\item{meanRatioMethod}{TRUE/FALSE} +\item{meanRatioMethod}{A logical with the default of \code{TRUE}. If \code{TRUE}, then +the mean ratio is implemented instead of the total ratio. Search the +source code for the equations if more information is needed.} -\item{raw}{TRUE/FALSE, input to define whether or not to expand numbers in the csv file (column header "NumF" and "NumM")} +\item{raw}{Logical input to define whether or not to expand numbers in the csv file with a default +unexpanded sample numbers.} -\item{NAs2zero}{change NAs to zeros} +\item{NAs2zero}{A logical specifying if \code{NA}s should be changed to zeros. +The default is \code{TRUE}.} -\item{month}{month} +\item{month}{A single integer value between 1-12. A user input fleet +number to assign to the month column based on the expected +format for Stock Synthesis. See the Stock Synthesis manual for +more information. Default "Enter Month".} -\item{fleet}{fleet number} +\item{fleet}{A single integer value. A user input fleet +number to assign to the fleet column based on the expected +format for Stock Synthesis. Default "Enter Fleet".} -\item{partition}{partition for Stock Synthesis} +\item{partition}{Partition to assign the composition data based on the expected +format for Stock Synthesis. Partition of 0 indicates that the composition data +include all composition data, 1 for discarded composition data, and 2 for retained +fish only. Default of 0.} -\item{ageErr}{age error value for Stock Synthesis} +\item{ageErr}{Single interget value of ageing error +vector to apply to the age data based on +Stock Synthesis. Default "Enter".} -\item{returnSamps}{TRUE/FALSE stops the function after the sample size is calculated} +\item{returnSamps}{A logical with the default of \code{FALSE}. A value of \code{TRUE} +stops the function after the sample size is calculated.} -\item{printfolder}{folder where the length comps will be saved} +\item{printfolder}{A string that will be appended to \code{dir}, creating a folder +where the output will be saved. If specified as \code{""}, +the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} \item{verbose}{A logical that specifies if you want to print messages and warnings to the console. The default is \code{TRUE}.} } \description{ -Calculates proportion of age at length and reformats into SS format -Uses raw numbers at length, assuming that is a random sample conditioned on length and sex. -To use expanded numbers (up to strata areas), set raw=F -Only sex codes 1 and 2 and puts males and females on separate lines because the age@L is conditioned on sex (a sample of females of length 25cm, for example) -Gender=1: females only. Male values ignored -Gender=2: males only. Female values ignored. -lgthBins is either the interval between length bins or the actual length bins -note that 0 and Inf are tacked on the ends to account for lengths and ages outside the interval. You may want to add these in to first and last bin. -I assume all fish are sexed for age data, thus do not apply sex ratios for unsexed fish +Calculates conditional age-at-length composition data using raw numbers at length, +assuming that is a random sample conditioned on length and sex. } \seealso{ \code{\link{StrataFactors.fn}} diff --git a/man/SurveyLFs.fn.Rd b/man/SurveyLFs.fn.Rd index e0a378f..a4504eb 100644 --- a/man/SurveyLFs.fn.Rd +++ b/man/SurveyLFs.fn.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/SurveyLFs.fn.R \name{SurveyLFs.fn} \alias{SurveyLFs.fn} -\title{Expands the lengths up to the total stratum area then sums over strata} +\title{Expands the lengths up to the total stratum area then sums over strata for each year} \usage{ SurveyLFs.fn( dir = NULL, @@ -33,24 +33,23 @@ SurveyLFs.fn( ) } \arguments{ -\item{dir}{A file path to an existing directory where you would like to -create a folder to store the output from this function. The default is -\code{dir = NULL}, which causes the function to not save any files. You can -store the output directly in \code{dir} if you specify \code{printfolder = ""}.} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} \item{datL}{A data frame of length-composition data returned from -\code{\link[=PullBio.fn]{PullBio.fn()}}.} +\code{\link[=pull_bio]{pull_bio()}}.} -\item{datTows}{A data frame of catch data returned from \code{\link[=PullCatch.fn]{PullCatch.fn()}}.} +\item{datTows}{A data frame of catch data returned from \code{\link[=pull_catch]{pull_catch()}}.} -\item{strat.vars}{Variables in both \code{datL} and \code{datTows} that are used to +\item{strat.vars}{Variables in both data frame that are used to define the stratas. Default is bottom depth (m) and latitudes (decimal degrees), i.e., \code{c("Depth_m", "Latitude_dd")}.} \item{strat.df}{A data frame that defines the strata and provides the calculated areas for each strata returned from \code{\link[=createStrataDF.fn]{createStrataDF.fn()}}.} -\item{lgthBins}{An integer vector of length bins.} +\item{lgthBins}{Vector of length bins to create length compositions across. Values above or below the +minimum or maximum values, respectively, are grouped into the first size or plus group size.} \item{SSout}{A logical with the default of \code{TRUE}. If \code{TRUE}, the output is returned in a format that can be directly pasted into an SS3 data file.} @@ -59,12 +58,11 @@ is returned in a format that can be directly pasted into an SS3 data file.} the mean ratio is implemented instead of the total ratio. Search the source code for the equations if more information is needed.} -\item{sex}{(0, 1, 2, 3). The integer will be used to define the sex column +\item{sex}{Options of (0, 1, 2, 3). The integer will be used to define the sex column of the returned input for Stock Synthesis and specifies how the composition are treated with respect to sex. See the Stock Synthesis manual for more information. In short, 0 is for unsexed, 1 is females, 2 -is males, and 3 is males and females where the sex ratio of the samples is -informative to the model. The default is \code{3}.} +is males, and 3 is females and males. The default is \code{3}.} \item{NAs2zero}{A logical specifying if \code{NA}s should be changed to zeros. The default is \code{TRUE}.} @@ -83,21 +81,42 @@ based on the calculated sex ratio in the data.} \item{sexRatioStage}{(1, 2). The stage of the expansion to apply the sex ratio. The default is \code{1}.} -\item{partition, fleet, agelow, agehigh, ageErr, month}{Each argument requires a -single integer value that will be used to set the associated column of the -returned input for Stock Synthesis. See the Stock Synthesis manual for -more information.} +\item{partition}{Partition to assign the composition data based on the expected +format for Stock Synthesis. Partition of 0 indicates that the composition data +include all composition data, 1 for discarded composition data, and 2 for retained +fish only. Default of 0.} -\item{nSamps}{A named vector of input or effective sample sizes that will be -used to set the effective sample size of the returned input for Stock -Synthesis. A value must be supplied for every year of data in \code{datL}.} +\item{fleet}{A single integer value. A user input fleet +number to assign to the fleet column based on the expected +format for Stock Synthesis. Default "Enter Fleet".} + +\item{agelow}{Lower age bin for all age composition data based on the expected +format for Stock Synthesis. Default value of -1 which translates to the lowest age +bin.} + +\item{agehigh}{Upper age bin for all age composition data based on the expected +format for Stock Synthesis. Default value of -1 which translates to the highest} + +\item{ageErr}{Single interget value of ageing error +vector to apply to the age data based on +Stock Synthesis. Default "Enter".} + +\item{nSamps}{Vector of integer sample sizes. A vector of sample sizes for +all years in \code{datL} is required if a vector is provided. The input vector will be included in the +output marginal age composition data. One option for calculating input sample size is the \code{\link[=GetN.fn]{GetN.fn()}}. +The default is "Enter Samps".} + +\item{month}{A single integer value between 1-12. A user input fleet +number to assign to the month column based on the expected +format for Stock Synthesis. See the Stock Synthesis manual for +more information. Default "Enter Month".} \item{printfolder}{A string that will be appended to \code{dir}, creating a folder -where the length-composition output will be saved. If specified as \code{""}, -the output will just be saved directly in \code{dir}. The default is \code{"forSS"}.} +where the output will be saved. If specified as \code{""}, +the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} -\item{remove999}{A logical with the default of \code{TRUE}, which leads to the -output having the 999 column combined with the first length bin.} +\item{remove999}{The output object by the function will have the 999 column combined with the first length bin. +Default TRUE.} \item{outputStage1}{A logical specifying if you would like the function to stop after the end of the first stage of the expansion process and return @@ -111,13 +130,10 @@ to sum to 100. The default is \code{TRUE}.} warnings to the console. The default is \code{TRUE}.} } \description{ -Expands the lengths up to the total stratum area then sums over strata -} -\details{ -The original version was written by Allan Hicks 16 March 2009. This function -has since been modified by Chantel Wetzel to work with the data warehouse -data formatting, add additional options of when to apply the sex ratio, and -correct some treatment of unsexed fish weighted by sample size and area. +Create expanded length composition data based on the pre-specified strata. +This function is designed to be used with catch pulled using \code{\link[=pull_catch]{pull_catch()}} and +biological data pulled using \code{\link[=pull_bio]{pull_bio()}}. The default output is formatted based +on the formatting required by Stock Synthesis. } \seealso{ \itemize{ diff --git a/man/UnexpandedAFs.fn.Rd b/man/UnexpandedAFs.fn.Rd index bf49134..a2f0d8c 100644 --- a/man/UnexpandedAFs.fn.Rd +++ b/man/UnexpandedAFs.fn.Rd @@ -2,8 +2,7 @@ % Please edit documentation in R/UnexpandedAF.fn.R \name{UnexpandedAFs.fn} \alias{UnexpandedAFs.fn} -\title{Creates a matrix of length or age composition data WITHOUT expantion -Written by Chantel Wetzel to work with the data warehouse data formatting,} +\title{Creates a matrix of unexpanded age compositions} \usage{ UnexpandedAFs.fn( dir = NULL, @@ -21,34 +20,55 @@ UnexpandedAFs.fn( ) } \arguments{ -\item{dir}{directory this is where the output files will be saved} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{datA}{the read in length comps by the PullBio.fn function} +\item{datA}{A data frame of length-composition data returned from +\code{\link[=pull_bio]{pull_bio()}}.} -\item{ageBins}{length bins} +\item{ageBins}{Vector of age bins to create age compositions across. Values above or below the +minimum or maximum values, respectively, are grouped into the first age or plus group age.} -\item{sex}{(0 = unsexed, 1 = females, 2 = males, 3 = females then males) sex value for Stock Synthesis} +\item{sex}{Options of (0, 1, 2, 3). The integer will be used to define the sex column +of the returned input for Stock Synthesis and specifies how the +composition are treated with respect to sex. See the Stock Synthesis +manual for more information. In short, 0 is for unsexed, 1 is females, 2 +is males, and 3 is females and males. The default is \code{3}.} -\item{partition}{partition for Stock Synthesis} +\item{partition}{Partition to assign the composition data based on the expected +format for Stock Synthesis. Partition of 0 indicates that the composition data +include all composition data, 1 for discarded composition data, and 2 for retained +fish only. Default of 0.} -\item{fleet}{fleet number} +\item{fleet}{A single integer value. A user input fleet +number to assign to the fleet column based on the expected +format for Stock Synthesis. Default "Enter Fleet".} -\item{ageErr}{Number of ageing error matrix for SS} +\item{ageErr}{Single interget value of ageing error +vector to apply to the age data based on +Stock Synthesis. Default "Enter".} -\item{agelow}{age bin for SS (default value of -1)} +\item{agelow}{Lower age bin for all age composition data based on the expected +format for Stock Synthesis. Default value of -1 which translates to the lowest age +bin.} -\item{agehigh}{age bin for SS (default value of -1)} +\item{agehigh}{Upper age bin for all age composition data based on the expected +format for Stock Synthesis. Default value of -1 which translates to the highest} -\item{month}{month the samples were collected} +\item{month}{A single integer value between 1-12. A user input fleet +number to assign to the month column based on the expected +format for Stock Synthesis. See the Stock Synthesis manual for +more information. Default "Enter Month".} -\item{printfolder}{folder where the length comps will be saved} +\item{printfolder}{A string that will be appended to \code{dir}, creating a folder +where the output will be saved. If specified as \code{""}, +the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} \item{verbose}{A logical that specifies if you want to print messages and warnings to the console. The default is \code{TRUE}.} } \description{ -Creates a matrix of length or age composition data WITHOUT expantion -Written by Chantel Wetzel to work with the data warehouse data formatting, +Creates a matrix of unexpanded age compositions } \author{ Chantel Wetzel diff --git a/man/UnexpandedLFs.fn.Rd b/man/UnexpandedLFs.fn.Rd index 8d704f0..73b85f1 100644 --- a/man/UnexpandedLFs.fn.Rd +++ b/man/UnexpandedLFs.fn.Rd @@ -2,8 +2,7 @@ % Please edit documentation in R/unexpandedLF.fn.R \name{UnexpandedLFs.fn} \alias{UnexpandedLFs.fn} -\title{Creates a matrix of length or age composition data WITHOUT expantion -Written by Chantel Wetzel to work with the data warehouse data formatting,} +\title{Creates a matrix of unexpanded length composition data} \usage{ UnexpandedLFs.fn( dir = NULL, @@ -21,34 +20,55 @@ UnexpandedLFs.fn( ) } \arguments{ -\item{dir}{directory this is where the output files will be saved} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{datL}{the read in length comps by the PullBio.fn function} +\item{datL}{A data frame of length-composition data returned from +\code{\link[=pull_bio]{pull_bio()}}.} -\item{lgthBins}{length bins} +\item{lgthBins}{Vector of length bins to create length compositions across. Values above or below the +minimum or maximum values, respectively, are grouped into the first size or plus group size.} -\item{sex}{(0 = unsexed, 1 = females, 2 = males, 3 = females then males) sex value for Stock Synthesis} +\item{sex}{Options of (0, 1, 2, 3). The integer will be used to define the sex column +of the returned input for Stock Synthesis and specifies how the +composition are treated with respect to sex. See the Stock Synthesis +manual for more information. In short, 0 is for unsexed, 1 is females, 2 +is males, and 3 is females and males. The default is \code{3}.} -\item{partition}{partition for Stock Synthesis} +\item{partition}{Partition to assign the composition data based on the expected +format for Stock Synthesis. Partition of 0 indicates that the composition data +include all composition data, 1 for discarded composition data, and 2 for retained +fish only. Default of 0.} -\item{fleet}{fleet number} +\item{fleet}{A single integer value. A user input fleet +number to assign to the fleet column based on the expected +format for Stock Synthesis. Default "Enter Fleet".} -\item{ageErr}{Number of ageing error matrix for SS} +\item{ageErr}{Single interget value of ageing error +vector to apply to the age data based on +Stock Synthesis. Default "Enter".} -\item{agelow}{age bin for SS (default value of -1)} +\item{agelow}{Lower age bin for all age composition data based on the expected +format for Stock Synthesis. Default value of -1 which translates to the lowest age +bin.} -\item{agehigh}{age bin for SS (default value of -1)} +\item{agehigh}{Upper age bin for all age composition data based on the expected +format for Stock Synthesis. Default value of -1 which translates to the highest} -\item{month}{month the samples were collected} +\item{month}{A single integer value between 1-12. A user input fleet +number to assign to the month column based on the expected +format for Stock Synthesis. See the Stock Synthesis manual for +more information. Default "Enter Month".} -\item{printfolder}{folder where the length comps will be saved} +\item{printfolder}{A string that will be appended to \code{dir}, creating a folder +where the output will be saved. If specified as \code{""}, +the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} \item{verbose}{A logical that specifies if you want to print messages and warnings to the console. The default is \code{TRUE}.} } \description{ -Creates a matrix of length or age composition data WITHOUT expantion -Written by Chantel Wetzel to work with the data warehouse data formatting, +Creates a matrix of unexpanded length composition data } \author{ Chantel Wetzel diff --git a/man/check_dir.Rd b/man/check_dir.Rd index bae0f76..2285a6d 100644 --- a/man/check_dir.Rd +++ b/man/check_dir.Rd @@ -7,7 +7,7 @@ check_dir(dir, verbose = TRUE) } \arguments{ -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} \item{verbose}{A logical that specifies if you want to print messages and diff --git a/man/pull_bio.Rd b/man/pull_bio.Rd index 4d99df5..57e1a63 100644 --- a/man/pull_bio.Rd +++ b/man/pull_bio.Rd @@ -71,7 +71,7 @@ Data can only be pulled from one survey at a time, though we are working on allowing for a vector of survey names. Currently, \code{NWFSC.Shelf.Rockfish} and \code{NWFSC.Hook.Line} are not supported.} -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} \item{convert}{TRUE/FALSE to convert column names to first letter uppercase diff --git a/man/pull_biological_samples.Rd b/man/pull_biological_samples.Rd index 7900d80..533c4d2 100644 --- a/man/pull_biological_samples.Rd +++ b/man/pull_biological_samples.Rd @@ -73,7 +73,7 @@ Data can only be pulled from one survey at a time, though we are working on allowing for a vector of survey names. Currently, \code{NWFSC.Shelf.Rockfish} and \code{NWFSC.Hook.Line} are not supported.} -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} \item{verbose}{A logical that specifies if you want to print messages and diff --git a/man/pull_catch.Rd b/man/pull_catch.Rd index 8b95eda..559bbbb 100644 --- a/man/pull_catch.Rd +++ b/man/pull_catch.Rd @@ -68,7 +68,7 @@ Data can only be pulled from one survey at a time, though we are working on allowing for a vector of survey names. Currently, \code{NWFSC.Shelf.Rockfish} and \code{NWFSC.Hook.Line} are not supported.} -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} \item{convert}{TRUE/FALSE to convert column names to first letter uppercase diff --git a/man/pull_gemm.Rd b/man/pull_gemm.Rd index 13612eb..8d72d1b 100644 --- a/man/pull_gemm.Rd +++ b/man/pull_gemm.Rd @@ -26,7 +26,7 @@ Use the \code{sci_name} argument if you know the latin name.} range of years to pull data for (e.g., c(2003, 2024)). Vector can not contain -Inf or Inf.} -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} } \description{ diff --git a/man/pull_haul.Rd b/man/pull_haul.Rd index 741d098..6cb679e 100644 --- a/man/pull_haul.Rd +++ b/man/pull_haul.Rd @@ -48,7 +48,7 @@ Data can only be pulled from one survey at a time, though we are working on allowing for a vector of survey names. Currently, \code{NWFSC.Shelf.Rockfish} and \code{NWFSC.Hook.Line} are not supported.} -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} \item{verbose}{A logical that specifies if you want to print messages and diff --git a/man/save_rdata.Rd b/man/save_rdata.Rd index 1ae7c3d..c714cc8 100644 --- a/man/save_rdata.Rd +++ b/man/save_rdata.Rd @@ -9,7 +9,7 @@ save_rdata(x, dir = NULL, name_base, verbose = TRUE) \arguments{ \item{x}{An object.} -\item{dir}{directory where ouptut will be saved. The directory where the file should be saved. +\item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} \item{name_base}{A string that will be appended to with the system time and From 677aa148c18f78a2b2d812b3c850d26de8618973 Mon Sep 17 00:00:00 2001 From: Chantel Wetzel Date: Wed, 8 May 2024 08:17:51 -0700 Subject: [PATCH 4/6] Add function documentation and examples --- R/Biomass.fn.R | 33 +++++++++++-- R/Format.AKSlope.fn.R | 3 ++ R/GetN.fn.R | 20 +++++++- R/GetSpp.fn.R | 3 +- R/GetSppDefault.fn.R | 3 +- R/GetStrata.fn.R | 1 + R/GetSurveyAbb.fn.R | 1 + R/PlotPresenceAbsence.fn.R | 4 +- R/PlotSexRatioStrata.fn.R | 5 +- R/PullBio.fn.R | 14 +++--- R/PullCatch.fn.R | 16 +++---- R/PullHaul.fn.R | 10 ++-- R/ReadInAges.fn.R | 14 ++++-- R/SexRatio.fn.R | 21 +++++---- R/SurveyAFs.fn.R | 1 + R/checkStrata.fn.R | 4 ++ R/check_dir.R | 5 +- R/createStrataDF.fn.R | 1 + R/est_growth.R | 52 ++++++++++----------- R/est_weight_length.R | 16 +++---- R/fit_vbgrowth.R | 7 +-- R/get_json.R | 1 + R/plotBio.fn.R | 5 +- R/plotBioStrata.fn.R | 5 +- R/plotFreqData.fn.R | 2 +- R/plotSexRatio.fn.R | 39 +++++++++------- R/plot_comps.R | 64 ++++++++++++------------- R/plot_cpue.R | 96 +++++++++++++++++++------------------- R/plot_varlenage.R | 36 ++++++++------ R/pull_bio.R | 16 ++++--- R/pull_haul.R | 10 ++-- 31 files changed, 295 insertions(+), 213 deletions(-) diff --git a/R/Biomass.fn.R b/R/Biomass.fn.R index de6f6bb..81617ff 100644 --- a/R/Biomass.fn.R +++ b/R/Biomass.fn.R @@ -1,5 +1,6 @@ #' Calculates design based estimates from survey data for West Coast surveys. #' +#' @details #' The design based index is calculated based on the area of the strata and #' the mean catch by strata. This function returns a list of design-based #' estimates by strata and estimates combined across stratas by year. This @@ -8,24 +9,48 @@ #' See: Gunderson, D.R. and Sample, T.M. 1980. Distribution and abundance of rockfish off Washington, #' Oregon, and California during 1977. Marine Fisheries Review: March - April. #' -#' #' @template dir #' @param dat Data frame of catch data that has been created by the [pull_catch()]. #' @template strat.vars #' @template strat.df #' @template printfolder -#' @param outputMedian Specify whether to output median or the mean biomass estimate. Default `TRUE`. +#' @param outputMedian Logical input to specify whether to output median or the +#' mean biomass estimate. Default `TRUE`. #' @template month -#' @param fleet fleet number for SS +#' @template fleet f #' @template verbose #' +#' @returns List of biomass estimates by year, biomass estimates by year and +#' strata, and numbers of fish by year. +#' #' @author Allan Hicks and Chantel Wetzel #' @importFrom grDevices dev.off png rgb #' @importFrom graphics axis legend mtext par plot points segments symbols #' @importFrom stats optim qnorm sd var #' @importFrom utils write.csv #' @export - +#' +#' @example +#' \dontrun{ +#' catch <- pull_catch( +#' common_name = "petrale sole", +#' survey = "NWFSC.Combo +#' ) +#' +#' strata <- CreateStrataDF.fn( +#' names=c("shallow_wa", "shallow_or", "shallow_ca", "deep_wa", "deep_or", "deep_ca"), +#' depths.shallow = c( 55, 55, 55, 183, 183, 183), +#' depths.deep = c(183, 183, 183, 549, 549, 549), +#' lats.south = c(46.0, 42.0, 32.0, 46.0, 42.0, 32.0), +#' lats.north = c(49.0, 46.0, 42.0, 49.0, 46.0, 42.0)) +#' +#' biommass <- Biomass.fn( +#' dat = catch, +#' strat.df = strata +#' ) +#' +#' } +#' Biomass.fn <- function( dir = NULL, dat, diff --git a/R/Format.AKSlope.fn.R b/R/Format.AKSlope.fn.R index c80b243..d807604 100644 --- a/R/Format.AKSlope.fn.R +++ b/R/Format.AKSlope.fn.R @@ -1,3 +1,6 @@ +#' Rename AFSC slope survey columns from data pulled before 2017 +#' +#' @details #' Rename columns in the AFSC slope survey data file #' received prior to the creation of the NWFSC data #' warehouse. This function converts the older data files diff --git a/R/GetN.fn.R b/R/GetN.fn.R index 31aab80..ca158b1 100644 --- a/R/GetN.fn.R +++ b/R/GetN.fn.R @@ -8,7 +8,7 @@ #' [10.1139/cjfas-2013-0289](https://doi.org/10.1139/cjfas-2013-0289). #' #' @template dir -#' @param dat A `data.frame` of composition data created using [pull_bio()]. +#' @param dat A data frame of composition data created using [pull_bio()]. #' @param type A string specifying whether doing "length" or "age" that is #' used to ensure the sample size is of the correct column and create #' the file name of the saved sheet. @@ -25,7 +25,23 @@ #' #' @author Chantel R. Wetzel #' @export - +#' +#' @examples +#' \dontrun{ +#' bio <- pull_bio( +#' common_name = "petrale sole", +#' survey = "NWFSC.Combo" +#' ) +#' +#' n <- GetN.fn( +#' dat = bio, +#' type = "length", +#' species = "flatfish" +#' ) +#' +#' } +#' +#' GetN.fn <- function( dir = NULL, dat, diff --git a/R/GetSpp.fn.R b/R/GetSpp.fn.R index b0d638d..6397509 100644 --- a/R/GetSpp.fn.R +++ b/R/GetSpp.fn.R @@ -1,5 +1,6 @@ #' Get Species Information #' +#' @details #' Get the scientific name, common name, and strata group for #' a vector of species. #' @@ -76,7 +77,7 @@ GetSpp.fn <- function(species, unident = FALSE) { c("coast", "stripetail_rockfish"), c("coast", "widow_rockfish"), c("coast", "yelloweye_rockfish"), - c("north_south", "yellowtail_rockfish") + c("north_south", "yellowtail_rockfish") )) row.names(spplist) <- NULL diff --git a/R/GetSppDefault.fn.R b/R/GetSppDefault.fn.R index b9e2f6c..71a58d5 100644 --- a/R/GetSppDefault.fn.R +++ b/R/GetSppDefault.fn.R @@ -1,5 +1,6 @@ #' Get Vector of Default Species Names for US West Coast #' +#' @details #' A standard list of common names for species of interest to the #' US West Coast. This list does not reflect ecosystem or financial #' importance, and instead it is strictly a list of species for which @@ -11,7 +12,7 @@ #' @examples #' GetSppDefault.fn() GetSppDefault.fn <- function() { - sp.list <- c( + sp.list <- c( "arrowtooth_flounder", "aurora_rockfish", "big_skate", diff --git a/R/GetStrata.fn.R b/R/GetStrata.fn.R index 681e769..44380ac 100644 --- a/R/GetStrata.fn.R +++ b/R/GetStrata.fn.R @@ -1,5 +1,6 @@ #' Get Default Strata #' +#' @details #' Get a data frame of strata for design-based estimates and survey #' composition data. Several strata are available for different default areas, #' as well as combinations using \code{"_"} in the argument \code{area}. diff --git a/R/GetSurveyAbb.fn.R b/R/GetSurveyAbb.fn.R index 9aaa0a1..a350853 100644 --- a/R/GetSurveyAbb.fn.R +++ b/R/GetSurveyAbb.fn.R @@ -1,5 +1,6 @@ #' Get Survey Abbreviation #' +#' @details #' Get abbreviations for a vector of survey names. The input vector of #' names, which are typically names used to pull the data from the #' warehouse, do not always match the name agreed upon within the diff --git a/R/PlotPresenceAbsence.fn.R b/R/PlotPresenceAbsence.fn.R index febd94f..be27483 100644 --- a/R/PlotPresenceAbsence.fn.R +++ b/R/PlotPresenceAbsence.fn.R @@ -3,8 +3,8 @@ #' This function was deprecated in {nwfsc} version 2.1. Please use #' [plot_proportion()] instead. #' -#' @param data data.frame containing data per haul created by [PullCatch.fn()] -#' or biological data created by [PullBio.fn()] where the `dim = "sex"` must +#' @param data Data frame containing data per haul created by [pull_catch()] +#' or biological data created by [pull_bio()] where the `dim = "sex"` must #' be true for the latter. #' @param dim Dimension of interest, either "depth", "lat", or "sex". #' @template dir diff --git a/R/PlotSexRatioStrata.fn.R b/R/PlotSexRatioStrata.fn.R index a9136ea..a9eec05 100644 --- a/R/PlotSexRatioStrata.fn.R +++ b/R/PlotSexRatioStrata.fn.R @@ -3,7 +3,7 @@ #' @template dir #' @param dat A data frame of length-composition data returned from #' [pull_bio()]. -#' @param type length/age which data type to use +#' @param type Specify where to calculate the sex ration by length or age. #' @template strat.vars #' @template strat.df #' @param circleSize circle size @@ -24,7 +24,8 @@ PlotSexRatioStrata.fn <- function( strat.vars = c("Depth_m", "Latitude_dd"), strat.df = NULL, circleSize = 0.05, - dopng = lifecycle::deprecated(), ...) { + dopng = lifecycle::deprecated(), + ...) { if (lifecycle::is_present(dopng)) { lifecycle::deprecate_warn( diff --git a/R/PullBio.fn.R b/R/PullBio.fn.R index 72a4932..9404623 100644 --- a/R/PullBio.fn.R +++ b/R/PullBio.fn.R @@ -44,13 +44,13 @@ #' } #' PullBio.fn <- function( - Name = NULL, - SciName = NULL, - YearRange = c(1980, 5000), - SurveyName = NULL, - SaveFile = lifecycle::deprecated(), - Dir = NULL, - verbose = TRUE) { + Name = NULL, + SciName = NULL, + YearRange = c(1980, 5000), + SurveyName = NULL, + SaveFile = lifecycle::deprecated(), + Dir = NULL, + verbose = TRUE) { lifecycle::deprecate_soft( when = "2.3", diff --git a/R/PullCatch.fn.R b/R/PullCatch.fn.R index fd96572..6e6fef9 100644 --- a/R/PullCatch.fn.R +++ b/R/PullCatch.fn.R @@ -47,7 +47,7 @@ #' * NWFSC.Hook.Line (not yet working), #' * NWFSC.Video, #' * Triennial.Canada -#' +#' #' Currently, you must pull data one survey at a time, though we are working on #' allowing for a vector of survey names and #' `NWFSC.Shelf.Rockfish` and `NWFSC.Hook.Line` are not supported. @@ -89,13 +89,13 @@ #' } #' PullCatch.fn <- function( - Name = NULL, - SciName = NULL, - YearRange = c(1980, 5000), - SurveyName = NULL, - SaveFile = lifecycle::deprecated(), - Dir = NULL, - verbose = TRUE) { + Name = NULL, + SciName = NULL, + YearRange = c(1980, 5000), + SurveyName = NULL, + SaveFile = lifecycle::deprecated(), + Dir = NULL, + verbose = TRUE) { lifecycle::deprecate_soft( when = "2.3", diff --git a/R/PullHaul.fn.R b/R/PullHaul.fn.R index 5298290..63458f0 100644 --- a/R/PullHaul.fn.R +++ b/R/PullHaul.fn.R @@ -24,11 +24,11 @@ #' } #' PullHaul.fn <- function( - YearRange = c(1980, 5000), - SurveyName = NULL, - SaveFile = lifecycle::deprecated(), - Dir = NULL, - verbose = TRUE) { + YearRange = c(1980, 5000), + SurveyName = NULL, + SaveFile = lifecycle::deprecated(), + Dir = NULL, + verbose = TRUE) { lifecycle::deprecate_soft( when = "2.3", diff --git a/R/ReadInAges.fn.R b/R/ReadInAges.fn.R index 3efe555..a781f02 100644 --- a/R/ReadInAges.fn.R +++ b/R/ReadInAges.fn.R @@ -1,14 +1,18 @@ -#' Reads in the West Coast Trienial survey data and filters the data into what is necessary -#' It reads in data and makes sure only the species necessary are kept -#' may want to keep NA (blank in Excel) to select the zero tows -#' removeCAN is a flag if you want tows in Canadian waters removed +#' Cleans triennial survey data by year and area +#' +#' @details +#' Reads in the West Coast Trienial survey data and filters the data into what +#' is necessary. It reads in data and makes sure only the species necessary are +#' kept may want to keep NA (blank in Excel) to select the zero tows +#' removeCAN is a flag if you want tows in Canadian waters removed. #' #' Necessary column names #' SPECIES_CODE #' AGE #' #' @param dat data file name -#' @param subset_years specify the years to retain, default is NULL which will provide 1977, alternative input would be 1980:2002 to remove only 1977. +#' @param subset_years specify the years to retain, default is NULL which will +#' provide 1977, alternative input would be 1980:2002 to remove only 1977. #' @template verbose #' #' @author Allan Hicks and Chantel Wetzel diff --git a/R/SexRatio.fn.R b/R/SexRatio.fn.R index 0fd850a..5f087eb 100644 --- a/R/SexRatio.fn.R +++ b/R/SexRatio.fn.R @@ -1,5 +1,6 @@ #' Assign sex to unsexed fish based on fish with similar traits #' +#' @details #' Assign sex to fish that were sampled but not sexed based on the proportion #' of like fish that were female out of sexed fish. After assigning unsexed #' fish to males and females, new sample sizes of each sex are calculated and @@ -74,17 +75,19 @@ #' of sexed fish for near (i.e., plus or minus one) measurement bins away #' across all years and strata. #' -SexRatio.fn <- function(x, - sexRatioStage, - sexRatioUnsexed, - maxSizeUnsexed, - bins = NULL, - verbose = TRUE) { +SexRatio.fn <- function( + x, + sexRatioStage, + sexRatioUnsexed, + maxSizeUnsexed, + bins = NULL, + verbose = TRUE) { + if (sexRatioStage == 1) { # incorporate unsexed fish using sex ratios if (length(sexRatioUnsexed) == 1 & !is.na(sexRatioUnsexed)) { if (verbose) { - message("Sex ratio for unsexed fish being applied to the expanded numbers within a tow (stage 1) when possible. + message("Sex ratio for unsexed fish being applied to the expanded numbers within a tow (stage 1) when possible. If no data within a tow for bin then the sex ratio for the bin across all years applied to unsexed fish. If no data for that bin across all years then the sex ratio for nearby bins was applied to unsexed fish.\n") } @@ -149,13 +152,13 @@ SexRatio.fn <- function(x, # These lines change to add the actual unsexed fish to the expansion factors -CRW x$expF <- x$expF + x$sexRatio * x$expU x$expM <- x$expM + (1 - x$sexRatio) * x$expU - x$expU <- x$expU - x$sexRatio * x$expU - (1 - x$sexRatio) * x$expU + x$expU <- x$expU - x$sexRatio * x$expU - (1 - x$sexRatio) * x$expU } } if (sexRatioStage == 2) { if (verbose) { - message("Sex ratio for unsexed fish being applied to the expanded numbers within a strata and year (stage 2). + message("Sex ratio for unsexed fish being applied to the expanded numbers within a strata and year (stage 2). If no data within a strata and year for bin then the sex ratio for the bin across all years and strata applied to unsexed fish.\n") } # Take everything out of the list into a dataframe diff --git a/R/SurveyAFs.fn.R b/R/SurveyAFs.fn.R index 6fcd4c8..edc7407 100644 --- a/R/SurveyAFs.fn.R +++ b/R/SurveyAFs.fn.R @@ -1,5 +1,6 @@ #' Create marginal age composition data #' +#' @details #' Create expanded marginal age composition data based on the pre-specified strata. #' This function is designed to be used with catch pulled using [pull_catch()] and #' biological data pulled using [pull_bio()]. The default output is formatted based diff --git a/R/checkStrata.fn.R b/R/checkStrata.fn.R index 990ecd2..6bbb160 100644 --- a/R/checkStrata.fn.R +++ b/R/checkStrata.fn.R @@ -1,5 +1,6 @@ #' Calculate the number of observations by year and strata #' +#' @details #' Calculates and returns the total number of tows and #' positive tows conducted in each strata by year. The #' selected stratas are used to expand the length and @@ -14,6 +15,9 @@ #' @template printfolder #' @template verbose #' +#' @return A matrix with the number of tows within each strata by year and the +#' number of positive tows by strata and year. +#' #' @author Chantel Wetzel #' @export #' diff --git a/R/check_dir.R b/R/check_dir.R index a866391..8f606f8 100644 --- a/R/check_dir.R +++ b/R/check_dir.R @@ -1,9 +1,10 @@ #' Directory check #' +#' @details #' Check that #' 1. The user knows that the data will not be saved if `dir = NULL`. -#' 1. The directory exists if it can be created. -#' 1. The function fails if the directory cannot be created. +#' 2. The directory exists if it can be created. +#' 3. The function fails if the directory cannot be created. #' #' @template dir #' @template verbose diff --git a/R/createStrataDF.fn.R b/R/createStrataDF.fn.R index 385f21f..a9635a7 100644 --- a/R/createStrataDF.fn.R +++ b/R/createStrataDF.fn.R @@ -1,5 +1,6 @@ #' Create strata data frame using \code{\link{StrataAreas.fn}} #' +#' @details #' Create a data frame of strata formatted for use by models that need #' estimates of the area for each strata to expand estimates of abundance. #' Strata limits are provided by the user in terms of diff --git a/R/est_growth.R b/R/est_growth.R index e08a43f..fdecb5f 100644 --- a/R/est_growth.R +++ b/R/est_growth.R @@ -1,13 +1,13 @@ #' Estimate length-at-age using the von Bertanlaffy -#' parametization from Stock Synthesis. +#' parametization #' #' -#' @param dir Directory to save output. -#' @param dat The data loaded from the NWFSC database -#' @param return_df TRUE/FALSE If set to TRUE the dat data frame is +#' @template dir +#' @param dat Data frame of biological data from [pull_bio()] +#' @param return_df TRUE/FALSE If set to TRUE the dat data frame is #' returned with added columns for the estimated Lhat_low, Lhat_pred, and Lhat_high. #' @param bySex Logical to indicate if plot by sex -#' @param Par Dataframe of starting parameters for K, Linf, L0, CV0, and CV2 based on the +#' @param Par Data frame of starting parameters for K, Linf, L0, CV0, and CV2 based on the #' Stock Synthesis parameterization of von Bertanlaffy growth. #' @param estVB Logical. Estimate vonB growth to plot against predicted length. If F, it uses the paramters in \code{parStart}. #' @param bins The bins to put ages into. If NULL then simply uses the ages as recorded. @@ -23,7 +23,7 @@ #' @author Chantel Wetzel #' @export -est_growth <- function(dir = NULL, dat, return_df = TRUE, +est_growth <- function(dir = NULL, dat, return_df = TRUE, Par = data.frame(K = 0.13, Linf = 55, L0 = 15, CV0 = 0.10, CV1 = 0.10), bySex = TRUE, estVB = TRUE, bins = NULL, sdFactor = 1, dopng = lifecycle::deprecated()) { @@ -48,27 +48,27 @@ est_growth <- function(dir = NULL, dat, return_df = TRUE, if (bySex){ use_data <- which( - !is.na(dat$Length_cm) & - !is.na(dat$Age) + !is.na(dat$Length_cm) & + !is.na(dat$Age) ) la_data <- dat[use_data, ] sex_list <- list(which( - !is.na(dat$Length_cm) & + !is.na(dat$Length_cm) & !is.na(dat$Age) & - dat$Sex %in% c("F") + dat$Sex %in% c("F") ), which( - !is.na(dat$Length_cm) & + !is.na(dat$Length_cm) & !is.na(dat$Age) & - dat$Sex %in% c("M") + dat$Sex %in% c("M") ), which( - !is.na(dat$Length_cm) & + !is.na(dat$Length_cm) & !is.na(dat$Age) & - dat$Sex %in% c("U") + dat$Sex %in% c("U") )) la_data_list <- list( - female = la_data[la_data$Sex == "F", ], + female = la_data[la_data$Sex == "F", ], male = la_data[la_data$Sex == "M", ], unsexed = la_data[la_data$Sex == "U", ]) sex_vec = c("F", "M", "U") @@ -76,8 +76,8 @@ est_growth <- function(dir = NULL, dat, return_df = TRUE, } else { use_data <- which( - !is.na(dat$Length_cm) & - !is.na(dat$Age) + !is.na(dat$Length_cm) & + !is.na(dat$Age) ) la_data <- dat[use_data, ] sex_list <- list(use_data) @@ -92,14 +92,14 @@ est_growth <- function(dir = NULL, dat, return_df = TRUE, xpar <- vector(mode = "list", length = nn) names(out) <- paste0(names(la_data_list), "_sd_cv") names(xpar) <- paste0(names(la_data_list), "_growth") - + # Loop by sex for (i in 1:length(la_data_list)) { if (estVB) { ests_log <- stats::optim(fn = fit_vbgrowth, par = log(Par), hessian = FALSE, - par_logspace = TRUE, + par_logspace = TRUE, Ages = la_data_list[[i]]$Age, Lengths = la_data_list[[i]]$Length_cm)$par xpar[[i]] <- exp(ests_log) @@ -111,10 +111,10 @@ est_growth <- function(dir = NULL, dat, return_df = TRUE, # Predicts from 1 to the maximum observed age by sex #predL <- VB.fn(1:max(la_data_list[[i]]$Age), xpar[1], xpar[2], xpar[3]) predL <- fit_vbgrowth( - Par = xpar[[i]], - par_logspace = FALSE, - Ages = la_data_list[[i]]$Age, - Lengths = la_data_list[[i]]$Length_cm, + Par = xpar[[i]], + par_logspace = FALSE, + Ages = la_data_list[[i]]$Age, + Lengths = la_data_list[[i]]$Length_cm, ReturnType = "Pred", sdFactor = sdFactor ) @@ -133,7 +133,7 @@ est_growth <- function(dir = NULL, dat, return_df = TRUE, } # end sex loop if (!is.null(dir)){ - save(xpar, file = file.path(dir, "growth_vonB_estimates.Rdata")) + save(xpar, file = file.path(dir, "growth_vonB_estimates.Rdata")) } ests <- c(xpar, out) @@ -141,7 +141,7 @@ est_growth <- function(dir = NULL, dat, return_df = TRUE, if(return_df){ return(dat) } else { - return(ests) + return(ests) } - + } diff --git a/R/est_weight_length.R b/R/est_weight_length.R index 05f77dd..b7a73d2 100644 --- a/R/est_weight_length.R +++ b/R/est_weight_length.R @@ -1,19 +1,19 @@ #' Calculate weight-length relationship parameters #' +#' @details #' Estimate parameters of the weight-length relationship for each #' sex and all sexes combined, where the latter includes unsexed fish. #' #' @param data A data frame containing empirical weights and lengths -#' from sampled fish. -#' Sexes should be available in the column `sex` or `SEX`. +#' from sampled fish. Sexes should be available in the column `sex` or `SEX`. #' @param col_length A numeric or character value specifying the column #' to use in `data` for length information. These lengths are assumed to #' be in centimeters. The default value is `lengthcm`, which is added -#' to a data set automatically when running [cleanPacFIN]. +#' to a data set automatically when running [cleanPacFIN()]. #' @param col_weight A numeric or character value specifying the column #' to use in `data` for weight information. These weights are assumed to #' be in kilograms The default value is `weightkg`, which is added -#' to a data set automatically when running [cleanPacFIN]. +#' to a data set automatically when running [cleanPacFIN()]. #' Using kilograms is the default because Stock Synthesis assumes the #' weight-length parameters are calculated using centimeters and kilograms. #' The reported values are easily scaled to give you results in grams if @@ -67,20 +67,20 @@ estimate_weight_length <- function( male = . %>% dplyr::filter(sex == "M"), all = . %>% dplyr::filter(sex %in% c(NA, "F", "M", "U", "H")) ) %>% - purrr::map_dfr(~ tidyr::nest(.x(data), data = everything()), + purrr::map_dfr(~ tidyr::nest(.x(data), data = everything()), .id = "group") %>% dplyr::mutate( - fits = purrr::map(data, ~ stats::lm(log(weight) ~ log(length_cm), + fits = purrr::map(data, ~ stats::lm(log(weight) ~ log(length_cm), data = .x))) - wghtlen_ests <- mresults %>% + wghtlen_ests <- mresults %>% dplyr::reframe( group = group, median_intercept = purrr::map_dbl(fits, ~ exp(.x$coefficients[1])), SD = purrr::map_dbl(fits, ~ sd(.x$residuals)), A = purrr::map_dbl(fits, ~ exp(.x$coefficients[1])*exp(0.5*sd(.x$residuals)^2)), B = purrr::map_dbl(fits, ~ .x$coefficients[2]) - ) %>% + ) %>% data.frame if (verbose) { diff --git a/R/fit_vbgrowth.R b/R/fit_vbgrowth.R index c7cd2d8..314a30a 100644 --- a/R/fit_vbgrowth.R +++ b/R/fit_vbgrowth.R @@ -1,5 +1,6 @@ #' Estimate von Bertanlaffy growth parameters from lengths and ages #' +#' @details #' Estimate von Bertanlaffy growth parameters from length and age data or #' predicted lengths given ages and input parameters. #' @@ -12,8 +13,8 @@ #' the lengths are just needed for estimation purpopses. If not \code{NULL}, #' ensure that there is one length measurement for every age measurement. #' Values of \code{NA} are accepted. -#' @param par_logspace TRUE/FALSE Indicates if the values in the \code{"Par"} are in -#' logspace and need to be converted back to normal spaces. +#' @param par_logspace TRUE/FALSE Indicates if the values in the \code{"Par"} are in +#' logspace and need to be converted back to normal spaces. #' @param ReturnType A single character value with \code{"NLL"} being the default, #' which leads to the negative log-likelihood value being returned. #' If \code{"Pred"}, then three values are returned @@ -68,7 +69,7 @@ fit_vbgrowth <- function(Par, Ages, Lengths, par_logspace = TRUE, ReturnType = c # negative when using optim. if(par_logspace == TRUE){ Par <- lapply(Par, exp) - } + } #### Parameters # Parameterized in terms of L0 instead of t0, where this parameterization was taken from diff --git a/R/get_json.R b/R/get_json.R index 7c860e0..14e522c 100644 --- a/R/get_json.R +++ b/R/get_json.R @@ -1,5 +1,6 @@ #' Get json content from a URL #' +#' @details #' Get information stored on the web in .json format using a URL. The content #' is first pulled from the web as text with UTF-8 encoding. Then the text #' is passed to [jsonlite::fromJSON()]. This workflow ensures that the URL diff --git a/R/plotBio.fn.R b/R/plotBio.fn.R index fbec07e..dab4b63 100644 --- a/R/plotBio.fn.R +++ b/R/plotBio.fn.R @@ -2,7 +2,8 @@ #' #' @template dir #' @param dat object created by the [Biomasss.fn()] -#' @param CI confidence interval +#' @param CI A numerical value that specifies the confidence interval to return. +#' Values should be between 0.01 to 0.99. #' @param scalar simply the divisor for the biomass #' @param gap a value that introduces a slight gap between the point estimate and the start of the line for the CI. A gap too large will invert the CI, making it look huge. You should know when this happens #' @param ylab y-axis text label @@ -17,7 +18,7 @@ #' no longer have to specify `dopng` to save the plot as a png. #' @param ... Additional arguments for the plots #' -#' @author Allan Hicks and John Wallace +#' @author Chantel Wetzel, Allan Hicks, and John Wallace #' @export PlotBio.fn <- function( diff --git a/R/plotBioStrata.fn.R b/R/plotBioStrata.fn.R index ed4ba35..55bcf52 100644 --- a/R/plotBioStrata.fn.R +++ b/R/plotBioStrata.fn.R @@ -2,7 +2,8 @@ #' #' @template dir #' @param dat Data frame created by the [Biomass.fn()] -#' @param CI confidence interval +#' @param CI A numerical value that specifies the confidence interval to return. +#' Values should be between 0.01 to 0.99. #' @param scalar simply the divisor for the biomass #' @param gap a value that introduces a slight gap between the point estimate and the start of the line for the CI. A gap too large will invert the CI, making it look huge. You should know when this happens #' @param ylab y-axis text label @@ -22,7 +23,7 @@ #' no longer have to specify `dopng` to save the plot as a png. #' @param ... Additional arguments for the plots #' -#' @author Allan Hicks and John Wallace +#' @author Chantel Wetzel, Allan Hicks, and John Wallace #' @export PlotBioStrata.fn <- function( diff --git a/R/plotFreqData.fn.R b/R/plotFreqData.fn.R index 0d662fc..fadf788 100644 --- a/R/plotFreqData.fn.R +++ b/R/plotFreqData.fn.R @@ -18,7 +18,7 @@ #' @param h Numeric figure height, defaults to 7 #' @param ... Additional arguments for the plots #' -#' @author Allan Hicks and Chantel Wetzel +#' @author Chantel Wetzel and Allan Hicks #' @export PlotFreqData.fn <- function( diff --git a/R/plotSexRatio.fn.R b/R/plotSexRatio.fn.R index 02e908e..5a79f67 100644 --- a/R/plotSexRatio.fn.R +++ b/R/plotSexRatio.fn.R @@ -1,9 +1,10 @@ #' Function to plot sex ratio #' -#' @param dir directory location for saving the png -#' @param dat data object -#' @param data.type "length" or "age" -#' @param main ame that will be used to name the saved png +#' @template dir +#' @param dat Data object with biological data from [pull_bio()] with a column +#' named `Sex` present. +#' @param data.type Specify where to calculate the sex ration by length or age. +#' @param main Name that will be used to name the saved png #' @param circleSize circle size #' @param dopng Deprecated with {nwfscSurvey} 2.1 because providing a non-NULL #' value to `dir` can serve the same purpose as `dopng = TRUE` without the @@ -15,13 +16,15 @@ #' @importFrom graphics abline #' @export -PlotSexRatio.fn <- function(dir, - dat, - data.type = "length", - main = NULL, - circleSize = 0.1, - dopng = lifecycle::deprecated(), - ...) { +PlotSexRatio.fn <- function( + dir, + dat, + data.type = "length", + main = NULL, + circleSize = 0.1, + dopng = lifecycle::deprecated(), + ...) { + if (lifecycle::is_present(dopng)) { lifecycle::deprecate_warn( when = "2.1", @@ -50,7 +53,7 @@ PlotSexRatio.fn <- function(dir, f(x / accuracy) * accuracy } - if (data.type == "length") { + if (data.type == "length") { bin_width <- 2 dat$bin <- round_any(dat$Length_cm, bin_width, floor) axis.name <- "Length (cm)" @@ -69,14 +72,14 @@ PlotSexRatio.fn <- function(dir, plot(x = names(ratioF), y = ratioF, type = "l", col = "red", lty = 2, xlab = axis.name, ylim = c(0, 1), main = main, ylab = "Fraction female", ...) abline(h = 0.50, col = "grey", lty = 2, lwd = 2) - symbols(x = names(ratioF), y = ratioF, circles = nobs, - inches = circleSize, fg = "red", bg = rgb(1, 0, 0, alpha = 0.5), + symbols(x = names(ratioF), y = ratioF, circles = nobs, + inches = circleSize, fg = "red", bg = rgb(1, 0, 0, alpha = 0.5), add = TRUE) test <- dplyr::count(dat, bin, Sex) %>% mutate(Proportion = n / sum(n)) - p <- ggplot(test, aes(x = bin, y = Proportion, fill = Sex)) + + p <- ggplot(test, aes(x = bin, y = Proportion, fill = Sex)) + geom_bar(position = "fill", stat = "identity") + geom_hline(yintercept = 0.50, col = 'white', lwd = 2) + scale_fill_manual(values = c('F' = 'red', 'M' = 'blue', 'U' = "forestgreen")) + @@ -85,12 +88,12 @@ PlotSexRatio.fn <- function(dir, panel.background = element_blank(), axis.title.x = element_text (size = 15), axis.title.y = element_text (size = 15), - axis.text.x = element_text(size = 15), + axis.text.x = element_text(size = 15), axis.text.y = element_text(size = 15)) print(p) if (!is.null(dir)){ - ggsave(filename = file.path(dir, "plots", paste0("proportion_by_", data.type, "_sex.png")), - width = 7, height = 7, units = 'in') + ggsave(filename = file.path(dir, "plots", paste0("proportion_by_", data.type, "_sex.png")), + width = 7, height = 7, units = 'in') } } diff --git a/R/plot_comps.R b/R/plot_comps.R index 0323f29..2075d79 100644 --- a/R/plot_comps.R +++ b/R/plot_comps.R @@ -1,8 +1,6 @@ #' Plot frequency data as bubble plots #' -#' @param dir Directory to save files to. The default is `NULL`, which leads to -#' the figures being printed to the screen rather than saved. If a path is -#' provided, then the figures will only be saved, i.e., not printed. +#' @template dir #' @param data Data file object created by [SurveyLF.fn()] or [SurveyAF.fn()]. #' @param add_save_name Option to add text to a saved figure name. This option #' can be useful if creating plots across multiple species and saving them @@ -30,14 +28,14 @@ #' #' @examples #' \dontrun{ plot_comps(data = LFs)} -#' +#' plot_comps <- function( - data, - dir = NULL, + data, + dir = NULL, add_save_name = NULL, - plot = 1:2, + plot = 1:2, add_0_ylim = TRUE, - width = 10, + width = 10, height = 7) { data_type <- ifelse(sum(names(data) == "ageErr") == 0, "length", "age") @@ -50,14 +48,14 @@ plot_comps <- function( plotdir <- file.path(dir, "plots") check_dir(dir = plotdir) - + plot_names <- file.path( plotdir, paste0( add_save_name, ifelse(test = is.null(add_save_name), yes = "", no = "_"), c(paste0(data_type,"_frequency_sex_", sex_type,".png"), - paste0(data_type, "_r4ss_frequency_sex_", sex_type,".png") ) + paste0(data_type, "_r4ss_frequency_sex_", sex_type,".png") ) ) ) @@ -65,8 +63,8 @@ plot_comps <- function( sex <- unique(data$sex) if (length(sex) > 1 ){ stop("This function does not work on processed composition - files with multiple Stock Synthesis sex specifications - (sex = 0, sex = 1, sex = 3). Please filter file down to + files with multiple Stock Synthesis sex specifications + (sex = 0, sex = 1, sex = 3). Please filter file down to a single sex and re-run.") } if (data_type == "length") { @@ -81,19 +79,19 @@ plot_comps <- function( comps <- comps[, -match(".999", names(comps))] } - # Check to see if the unsexed or single sexed comps are + # Check to see if the unsexed or single sexed comps are # double printed if (sum(grepl(".", colnames(comps), fixed = TRUE)) > 0 ) { comps <- comps[, !grepl(".", colnames(comps), fixed = TRUE)] } - + # Determine if entries are proportions (e.g., sum to 1 or 100) # and convert if needed if (sum(as.numeric(comps[1, ])) == 100) { comps <- 100 * comps / apply(comps, 1, sum) } if (sum(as.numeric(comps[1, ])) > 0.999 & sum(as.numeric(comps[1, ])) < 1.001) { - comps <- 100 * comps + comps <- 100 * comps } mod_comps <- cbind(year, comps) @@ -135,23 +133,23 @@ plot_comps <- function( range = c(1, 15), breaks = bub_range ) + - facet_grid(sex~.) + + facet_grid(sex~.) + scale_y_continuous( breaks = y_axis, limits = if (add_0_ylim) {c(0, NA)} else {NULL} ) + labs(x = "Year", y = ylabel, size = "Relative\nAbundance (%)", fill = "") + - theme(legend.key = element_blank(), + theme(legend.key = element_blank(), axis.title.x = element_text (size = 12), axis.title.y = element_text (size = 12), - axis.text.x = element_text(colour = "black", size = 12, angle = 90, vjust = 0.3, hjust = 1), - axis.text.y = element_text(colour = "black", size = 12), - legend.text = element_text(size = 10, colour ="black"), - legend.title = element_text(size = 12), - panel.background = element_blank(), - panel.border = element_rect(colour = "black", fill = NA, linewidth = 1), + axis.text.x = element_text(colour = "black", size = 12, angle = 90, vjust = 0.3, hjust = 1), + axis.text.y = element_text(colour = "black", size = 12), + legend.text = element_text(size = 10, colour ="black"), + legend.title = element_text(size = 12), + panel.background = element_blank(), + panel.border = element_rect(colour = "black", fill = NA, linewidth = 1), legend.position = "right") + - guides(size = "legend", color = "none", fill = "none") + guides(size = "legend", color = "none", fill = "none") if (!is.null(dir)) { ggsave(filename = plot_names[1], plot = p, width = width, height = height, units = "in" @@ -166,7 +164,7 @@ plot_comps <- function( df2 <- df df2$value <- df2$value / 100 df2[df2$sex == "MALE", 'value'] <- -1 * df2[df2$sex == "MALE", 'value'] - + p2 <- ggplot2::ggplot(df2, aes(x = variable, y = value)) + geom_line(aes(colour = sex), # add alpha = n inside the aes to shade by annual sample size lwd = 1.1) + @@ -175,15 +173,15 @@ plot_comps <- function( scale_color_manual(values = c('FEMALE' = 'darkred', 'MALE' = 'darkblue', 'UNSEXED' = "darkgreen")) + labs(x = ylabel, y = "Proportion") + geom_hline(yintercept = 0) + - theme(legend.key = element_blank(), + theme(legend.key = element_blank(), axis.title.x = element_text (size = 12), axis.title.y = element_text (size = 12), - axis.text.x = element_text(colour = "black", size = 12, angle = 90, vjust = 0.3, hjust = 1), - axis.text.y = element_text(colour = "black", size = 12), - legend.text = element_text(size = 10, colour ="black"), - legend.title = element_text(size = 12), - panel.background = element_blank(), - panel.border = element_rect(colour = "black", fill = NA, linewidth = 1), + axis.text.x = element_text(colour = "black", size = 12, angle = 90, vjust = 0.3, hjust = 1), + axis.text.y = element_text(colour = "black", size = 12), + legend.text = element_text(size = 10, colour ="black"), + legend.title = element_text(size = 12), + panel.background = element_blank(), + panel.border = element_rect(colour = "black", fill = NA, linewidth = 1), legend.position = "right") if (!is.null(dir)) { ggsave(filename = plot_names[2], plot = p2, @@ -193,5 +191,5 @@ plot_comps <- function( print(p2) } } - + } diff --git a/R/plot_cpue.R b/R/plot_cpue.R index f27cc15..a1f46b2 100644 --- a/R/plot_cpue.R +++ b/R/plot_cpue.R @@ -1,25 +1,25 @@ #' This function plots cpue and length by latitude and depth #' -#' @param dir Directory to save files to -#' @param catch Data catch file +#' @template dir +#' @param catch Data catch file pulled using [pull_catch()] #' @param plot A vector of integers specifying the figures you want. #' @param width Numeric figure width in inches, defaults to 7 #' @param height Numeric figure height in inches, defaults to 7 #' #' @import ggplot2 #' @import cowplot -#' +#' #' @author Chantel Wetzel #' @export -#' +#' plot_cpue <- function( - dir = NULL, - catch, - plot = 1:3, + dir = NULL, + catch, + plot = 1:3, width = 7, height = 7){ - # plot 1 = cpue by latitude and depth + # plot 1 = cpue by latitude and depth # plot 2 = cpue by lat and year # plot 3 = cpue by depth and year @@ -34,73 +34,73 @@ plot_cpue <- function( cd <- ggplot2::ggplot(catch[pos,], aes(x = Depth_m, y = log_cpue)) + geom_point(aes(size = log_cpue / size_adj), fill = 'darkorange', colour = 'darkorange', alpha = 0.75, shape = 21) + labs(x = "Depth (m)", y = "ln(CPUE)", size = "ln(CPUE)", fill = 'darkorange') + - geom_smooth(method = 'loess', color = 'darkgrey', lwd = 2) + + geom_smooth(method = 'loess', color = 'darkgrey', lwd = 2) + scale_x_continuous(n.breaks = 7) + scale_y_continuous(n.breaks = 7) + - theme(legend.key = element_blank(), - axis.text.x = element_text(colour = "black", size = 12), - axis.text.y = element_text(colour = "black", size = 11), - legend.text = element_text(size = 10, colour ="black"), - legend.title = element_text(size = 12), - panel.background = element_blank(), - panel.border = element_rect(fill = NA), + theme(legend.key = element_blank(), + axis.text.x = element_text(colour = "black", size = 12), + axis.text.y = element_text(colour = "black", size = 11), + legend.text = element_text(size = 10, colour ="black"), + legend.title = element_text(size = 12), + panel.background = element_blank(), + panel.border = element_rect(fill = NA), legend.position = "right") + guides(size = "legend", color = "none", fill = "none") # log(cpue) by latitude cl <- ggplot2::ggplot(catch[pos,], aes(x = Latitude_dd, y = log_cpue)) + geom_point(aes(size = log_cpue / size_adj), fill = 'darkorange', colour = 'darkorange', alpha = 0.75, shape = 21) + - geom_smooth(method = 'loess', color = 'darkgrey', lwd = 2) + + geom_smooth(method = 'loess', color = 'darkgrey', lwd = 2) + labs(x = "Latitude", y = "ln(CPUE)", size = "ln(CPUE)", fill = 'darkorange', colour = 'darkorange',) + scale_x_continuous(n.breaks = 7) + scale_y_continuous(n.breaks = 7) + - theme(legend.key = element_blank(), - axis.text.x = element_text(colour = "black", size = 12), - axis.text.y = element_text(colour = "black", size = 11), - legend.text = element_text(size = 10, colour ="black"), - legend.title = element_text(size = 12), - panel.background = element_blank(), - panel.border = element_rect(fill = NA), - legend.position = "right") + theme(legend.key = element_blank(), + axis.text.x = element_text(colour = "black", size = 12), + axis.text.y = element_text(colour = "black", size = 11), + legend.text = element_text(size = 10, colour ="black"), + legend.title = element_text(size = 12), + panel.background = element_blank(), + panel.border = element_rect(fill = NA), + legend.position = "right") cly <- ggplot2::ggplot(catch[pos,], aes(x = Latitude_dd, y = log_cpue)) + geom_point(aes(size = log_cpue / (100*size_adj)), fill = 'darkorange', colour = 'darkorange', alpha = 0.75, shape = 21) + - facet_wrap(facets = "Year") + - geom_smooth(method = 'loess', color = 'darkgrey', lwd = 2) + + facet_wrap(facets = "Year") + + geom_smooth(method = 'loess', color = 'darkgrey', lwd = 2) + labs(x = "Latitude", y = "ln(CPUE)", size = "ln(CPUE)", fill = 'darkorange', colour = 'darkorange',) + - guides(size = "legend", color = "none", fill = "none") + - theme(panel.background = element_blank(), + guides(size = "legend", color = "none", fill = "none") + + theme(panel.background = element_blank(), panel.border = element_rect(fill = NA)) # Length by depth and sex by year cdy <- ggplot2::ggplot(catch[pos, ], aes(x = Depth_m, y = log_cpue)) + geom_point(aes(size = log_cpue / (100*size_adj)), fill = 'darkorange', colour = 'darkorange', alpha = 0.75, shape = 21) + - facet_wrap(facets = "Year") + - geom_smooth(method = 'loess', color = 'darkgrey', lwd = 2) + + facet_wrap(facets = "Year") + + geom_smooth(method = 'loess', color = 'darkgrey', lwd = 2) + labs(x = "Depth (m)", y = "ln(CPUE)", size = "ln(CPUE)", fill = 'darkorange', colour = 'darkorange') + - guides(size = "legend", color = "none", fill = "none") + - theme(panel.background = element_blank(), + guides(size = "legend", color = "none", fill = "none") + + theme(panel.background = element_blank(), panel.border = element_rect(fill = NA)) # plot 1 cowplot::plot_grid(cl, cd, nrow = 2) - if(!is.null(dir)){ - ggsave(filename = file.path(dir, "plots", "cpue_by_lat_depth.png"), - width = width, height = height, units = 'in') - } + if(!is.null(dir)){ + ggsave(filename = file.path(dir, "plots", "cpue_by_lat_depth.png"), + width = width, height = height, units = 'in') + } # plot 2 print(cly) - if(!is.null(dir)){ - ggsave(filename = file.path(dir, "plots", "cpue_by_year_lat.png"), - width = width + 3, height = height + 3, units = 'in') - } + if(!is.null(dir)){ + ggsave(filename = file.path(dir, "plots", "cpue_by_year_lat.png"), + width = width + 3, height = height + 3, units = 'in') + } - # plot 3 + # plot 3 print(cdy) - if(!is.null(dir)){ - ggsave(filename = file.path(dir, "plots", "cpue_by_year_depth.png"), - width = width + 3, height = height + 3, units = 'in') - } - -} \ No newline at end of file + if(!is.null(dir)){ + ggsave(filename = file.path(dir, "plots", "cpue_by_year_depth.png"), + width = width + 3, height = height + 3, units = 'in') + } + +} diff --git a/R/plot_varlenage.R b/R/plot_varlenage.R index afc4096..09c5ee8 100644 --- a/R/plot_varlenage.R +++ b/R/plot_varlenage.R @@ -1,10 +1,12 @@ #' Plot variability of length at age #' -#' Plots the SD and CV of age at observed and predicted length +#' @details +#' Plots the standard deviation and coefficient of variation of age at observed +#' and predicted length #' #' -#' @param dir Directory to save output. -#' @param dat The data loaded from the NWFSC database +#' @template dir +#' @param dat The data loaded from [pull_bio()] #' @param main Name that will be used to name the saved png #' @param bySex Logical to indicate if plot by sex #' @param Par Starting parameters for K, Linf, L0, CV0, and CV2 based on the @@ -24,10 +26,18 @@ #' @author Chantel Wetzel #' @export -plot_varlenage <- function(dir = NULL, dat, main = NULL, +plot_varlenage <- function( + dir = NULL, + dat, + main = NULL, Par = data.frame(K = 0.13, Linf = 55, L0 = 15, CV0 = 0.10, CV1 = 0.10), - bySex = TRUE, estVB = TRUE, bins = NULL, legX = "bottomleft", legY = NULL, - dopng = lifecycle::deprecated(), ...) { + bySex = TRUE, + estVB = TRUE, + bins = NULL, + legX = "bottomleft", + legY = NULL, + dopng = lifecycle::deprecated(), + ...) { if (lifecycle::is_present(dopng)) { lifecycle::deprecate_warn( @@ -61,7 +71,7 @@ plot_varlenage <- function(dir = NULL, dat, main = NULL, par(mfcol = c(2, nn), mar = c(4, 4, 4, 4), oma = c(2, 2, 2, 2)) - ests <- est_growth(dir = dir, dat = dat, Par = Par, return_df = FALSE, + ests <- est_growth(dir = dir, dat = dat, Par = Par, return_df = FALSE, bySex = bySex, estVB = estVB, bins = bins) if (length(ests) > 2) { sex_names <- c("female", "male") @@ -81,9 +91,9 @@ plot_varlenage <- function(dir = NULL, dat, main = NULL, xsd <- ests[[num[i]]][, 2] xcv <- ests[[num[i]]][, 3] if (is.null(bins)) { - ages <- as.numeric(rownames(ests[[num[i]]])) + ages <- as.numeric(rownames(ests[[num[i]]])) } else { - ages <- bin[as.numeric(rownames(ests[[num[i]]]))] + ages <- bin[as.numeric(rownames(ests[[num[i]]]))] } plot(ages, xsd, col = colors[1], cex = 1.1, xlab = "Age", ylab = "SD of L@A", type = "b", pch = 16, lty = 1, main = names(la_data_list)[i], ...) @@ -92,10 +102,10 @@ plot_varlenage <- function(dir = NULL, dat, main = NULL, axis(4) mtext("CV", side = 4, line = 2.6) legend(bty = 'n', x = legX, y = legY, c("SD", "CV"), col = colors, pch = c(16, 3), lty = c(1, 2)) - plot(calc_vb(age = ages, k = xpar[1], Linf = xpar[2], L0 = xpar[3]), xsd, xlab = "Predicted Length at Age", ylab = "SD of L@A", + plot(calc_vb(age = ages, k = xpar[1], Linf = xpar[2], L0 = xpar[3]), xsd, xlab = "Predicted Length at Age", ylab = "SD of L@A", col = colors[1], cex = 1.1, type = "b", pch = 16, lty = 1, main = sex_names[i], ...) par(new = T) - plot(calc_vb(age = ages, k = xpar[1], Linf = xpar[2], L0 = xpar[3]), xcv, xlab = "", + plot(calc_vb(age = ages, k = xpar[1], Linf = xpar[2], L0 = xpar[3]), xcv, xlab = "", col = colors[2], cex = 1.1, ylab = "", yaxt = "n", type = "b", pch = 3, lty = 2, ...) axis(4) mtext("CV", side = 4, line = 2.6) @@ -105,7 +115,7 @@ plot_varlenage <- function(dir = NULL, dat, main = NULL, if (!is.null(dir)){ dev.off() - save(ests, file = file.path(dir, "growth_variance_vonB_estimates.Rdata")) + save(ests, file = file.path(dir, "growth_variance_vonB_estimates.Rdata")) } - + } diff --git a/R/pull_bio.R b/R/pull_bio.R index 5eb359e..aab8462 100644 --- a/R/pull_bio.R +++ b/R/pull_bio.R @@ -1,4 +1,5 @@ #' Pull biological data (age, length, weight) from the NWFSC data warehouse +#' #' The website is: https://www.webapps.nwfsc.noaa.gov/data #' This function can be used to pull a single species or all observed species #' In order to pull all species leave common_name or sci_name as NULL @@ -38,13 +39,14 @@ # "vermilion and sunset rockfish"), SurveyName = "NWFSC.Combo") #' } #' -pull_bio <- function(common_name = NULL, - sci_name = NULL, - years = c(1970, 2050), - survey, - dir = NULL, - convert = TRUE, - verbose = TRUE) { +pull_bio <- function( + common_name = NULL, + sci_name = NULL, + years = c(1970, 2050), + survey, + dir = NULL, + convert = TRUE, + verbose = TRUE) { options(timeout = 4000000) if (survey %in% c("NWFSC.Shelf.Rockfish", "NWFSC.Hook.Line")) { diff --git a/R/pull_haul.R b/R/pull_haul.R index 4c29222..bf97faf 100644 --- a/R/pull_haul.R +++ b/R/pull_haul.R @@ -1,4 +1,5 @@ #' Pull haul data from the NWFSC data warehouse. +#' #' The website is: https://www.webapps.nwfsc.noaa.gov/data. #' This function can be used to pull haul data and associated covariates. #' @@ -19,10 +20,11 @@ #' haul_data <- pull_haul() #' } #' -pull_haul <- function(years= c(1970, 2050), - survey, - dir = NULL, - verbose = TRUE) { +pull_haul <- function( + years= c(1970, 2050), + survey, + dir = NULL, + verbose = TRUE) { # increase the timeout period to avoid errors when pulling data options(timeout = 4000000) From 29f63418569142129cd8b0afa489698f2754ac7e Mon Sep 17 00:00:00 2001 From: Chantel Wetzel Date: Wed, 8 May 2024 08:18:07 -0700 Subject: [PATCH 5/6] add fxn input to align with other pull fxns --- R/pull_gemm.R | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/R/pull_gemm.R b/R/pull_gemm.R index 7bf2839..75ae007 100644 --- a/R/pull_gemm.R +++ b/R/pull_gemm.R @@ -1,18 +1,20 @@ #' Pull gemm data from the NWFSC data warehouse +#' #' The website is: https://www.webapps.nwfsc.noaa.gov/data -#' This function can be used to pull all gemm data, a single species, or a -#' subset of species c("Canary Rockfish", "Widow Rockfish"). Species names in -#' the gemm are capitalized (e.g. Canary Rockfish). However, there are checks in +#' This function can be used to pull all gemm data, a single species, or a +#' subset of species c("Canary Rockfish", "Widow Rockfish"). Species names in +#' the gemm are capitalized (e.g. Canary Rockfish). However, there are checks in #' the function to adjust input species names if the input names do not match -#' the expected capitalization (e.g. "canary rockfish", "canary_rockfish"). The -#' fuction also allows you to subset the data by year using the years input and to +#' the expected capitalization (e.g. "canary rockfish", "canary_rockfish"). The +#' fuction also allows you to subset the data by year using the years input and to #' save the object if the dir function input is given. #' #' @template common_name -#' @template years -#' @template dir +#' @template years +#' @template dir +#' @template verbose #' -#' @author Chantel Wetzel +#' @author Chantel Wetzel #' @export #' #' @import dplyr @@ -24,8 +26,8 @@ #' # Pull all GEMM data #' all_data <- pull_gemm() #' -#' # Pull for a specific specis -#' widow_data <- pull_gemm(common_name = "Widow Rockfish") +#' # Pull for a specific specis +#' widow_data <- pull_gemm(common_name = "widow rockfish") #' #' # Pull multiple species #' data <- pull_gemm(common_name = c("Widow Rockfish", "Canary Rockfish")) @@ -35,11 +37,17 @@ #' } #' #' -pull_gemm <- function(common_name, years, dir){ +pull_gemm <- function( + common_name, + years, + dir = NULL, + verbose = TRUE){ + + check_dir(dir = dir, verbose = verbose) # Pull all gemm data gemm <- utils::read.csv( - url("https://www.webapps.nwfsc.noaa.gov/data/api/v1/source/observer.gemm_fact/selection.csv"), + url("https://www.webapps.nwfsc.noaa.gov/data/api/v1/source/observer.gemm_fact/selection.csv"), encoding = 'UTF-8-BOM') %>% janitor::clean_names() @@ -66,7 +74,7 @@ pull_gemm <- function(common_name, years, dir){ gemm <- gemm[gemm$year %in% years, ] } - if(!missing(dir)) { + if(!is.null(dir)) { if(missing(common_name)){ save(gemm, file = paste0(dir, "/gemm_out.Rdat")) } else { From 34c305dc1998ab6208bbcdb33b0d292b2cbc7f44 Mon Sep 17 00:00:00 2001 From: Chantel Wetzel Date: Wed, 8 May 2024 08:21:49 -0700 Subject: [PATCH 6/6] doc --- R/Biomass.fn.R | 8 ++++---- man/Biomass.fn.Rd | 36 +++++++++++++++++++++++++++++++++-- man/CheckStrata.fn.Rd | 7 +++++++ man/CreateStrataDF.fn.Rd | 3 +++ man/Format.AKSlope.fn.Rd | 10 ++++------ man/GetN.fn.Rd | 19 +++++++++++++++++- man/GetSpp.fn.Rd | 3 +++ man/GetSppDefault.fn.Rd | 3 +++ man/GetStrata.fn.Rd | 3 +++ man/GetSurveyAbb.fn.Rd | 3 +++ man/PlotBio.fn.Rd | 5 +++-- man/PlotBioStrata.fn.Rd | 5 +++-- man/PlotFreqData.fn.Rd | 2 +- man/PlotPresenceAbsence.fn.Rd | 4 ++-- man/PlotSexRatio.fn.Rd | 10 ++++++---- man/PlotSexRatioStrata.fn.Rd | 2 +- man/ReadInAges.fn.Rd | 16 +++++++++++----- man/SexRatio.fn.Rd | 6 ++++-- man/SurveyAFs.fn.Rd | 3 +++ man/check_dir.Rd | 3 +++ man/est_growth.Rd | 11 ++++++----- man/estimate_weight_length.Rd | 10 ++++++---- man/fit_vbgrowth.Rd | 3 +++ man/get_json.Rd | 3 +++ man/plot_comps.Rd | 5 ++--- man/plot_cpue.Rd | 5 +++-- man/plot_varlenage.Rd | 11 ++++++++--- man/pull_bio.Rd | 6 +----- man/pull_gemm.Rd | 20 +++++++------------ man/pull_haul.Rd | 5 +---- 30 files changed, 159 insertions(+), 71 deletions(-) diff --git a/R/Biomass.fn.R b/R/Biomass.fn.R index 81617ff..a58b896 100644 --- a/R/Biomass.fn.R +++ b/R/Biomass.fn.R @@ -17,7 +17,7 @@ #' @param outputMedian Logical input to specify whether to output median or the #' mean biomass estimate. Default `TRUE`. #' @template month -#' @template fleet f +#' @template fleet #' @template verbose #' #' @returns List of biomass estimates by year, biomass estimates by year and @@ -30,15 +30,15 @@ #' @importFrom utils write.csv #' @export #' -#' @example +#' @examples #' \dontrun{ #' catch <- pull_catch( #' common_name = "petrale sole", -#' survey = "NWFSC.Combo +#' survey = "NWFSC.Combo" #' ) #' #' strata <- CreateStrataDF.fn( -#' names=c("shallow_wa", "shallow_or", "shallow_ca", "deep_wa", "deep_or", "deep_ca"), +#' names = c("shallow_wa", "shallow_or", "shallow_ca", "deep_wa", "deep_or", "deep_ca"), #' depths.shallow = c( 55, 55, 55, 183, 183, 183), #' depths.deep = c(183, 183, 183, 549, 549, 549), #' lats.south = c(46.0, 42.0, 32.0, 46.0, 42.0, 32.0), diff --git a/man/Biomass.fn.Rd b/man/Biomass.fn.Rd index 26e1447..450d325 100644 --- a/man/Biomass.fn.Rd +++ b/man/Biomass.fn.Rd @@ -33,19 +33,29 @@ calculated areas for each strata returned from \code{\link[=createStrataDF.fn]{c where the output will be saved. If specified as \code{""}, the output will just be saved directly in \code{dir}. The default is \code{"forSS3"}.} -\item{outputMedian}{Specify whether to output median or the mean biomass estimate. Default \code{TRUE}.} +\item{outputMedian}{Logical input to specify whether to output median or the +mean biomass estimate. Default \code{TRUE}.} \item{month}{A single integer value between 1-12. A user input fleet number to assign to the month column based on the expected format for Stock Synthesis. See the Stock Synthesis manual for more information. Default "Enter Month".} -\item{fleet}{fleet number for SS} +\item{fleet}{A single integer value. A user input fleet +number to assign to the fleet column based on the expected +format for Stock Synthesis. Default "Enter Fleet".} \item{verbose}{A logical that specifies if you want to print messages and warnings to the console. The default is \code{TRUE}.} } +\value{ +List of biomass estimates by year, biomass estimates by year and +strata, and numbers of fish by year. +} \description{ +Calculates design based estimates from survey data for West Coast surveys. +} +\details{ The design based index is calculated based on the area of the strata and the mean catch by strata. This function returns a list of design-based estimates by strata and estimates combined across stratas by year. This @@ -53,6 +63,28 @@ function is designed to work with data frames pulled from the NWFSC data warehouse using \code{\link[=pull_catch]{pull_catch()}}. See: Gunderson, D.R. and Sample, T.M. 1980. Distribution and abundance of rockfish off Washington, Oregon, and California during 1977. Marine Fisheries Review: March - April. +} +\examples{ +\dontrun{ +catch <- pull_catch( + common_name = "petrale sole", + survey = "NWFSC.Combo" +) + +strata <- CreateStrataDF.fn( + names = c("shallow_wa", "shallow_or", "shallow_ca", "deep_wa", "deep_or", "deep_ca"), + depths.shallow = c( 55, 55, 55, 183, 183, 183), + depths.deep = c(183, 183, 183, 549, 549, 549), + lats.south = c(46.0, 42.0, 32.0, 46.0, 42.0, 32.0), + lats.north = c(49.0, 46.0, 42.0, 49.0, 46.0, 42.0)) + +biommass <- Biomass.fn( + dat = catch, + strat.df = strata +) + +} + } \author{ Allan Hicks and Chantel Wetzel diff --git a/man/CheckStrata.fn.Rd b/man/CheckStrata.fn.Rd index 512a0f7..7232bc0 100644 --- a/man/CheckStrata.fn.Rd +++ b/man/CheckStrata.fn.Rd @@ -34,7 +34,14 @@ the output will just be saved directly in \code{dir}. The default is \code{"forS \item{verbose}{A logical that specifies if you want to print messages and warnings to the console. The default is \code{TRUE}.} } +\value{ +A matrix with the number of tows within each strata by year and the +number of positive tows by strata and year. +} \description{ +Calculate the number of observations by year and strata +} +\details{ Calculates and returns the total number of tows and positive tows conducted in each strata by year. The selected stratas are used to expand the length and diff --git a/man/CreateStrataDF.fn.Rd b/man/CreateStrataDF.fn.Rd index 2a4658d..2dca2df 100644 --- a/man/CreateStrataDF.fn.Rd +++ b/man/CreateStrataDF.fn.Rd @@ -33,6 +33,9 @@ The data frame will have six columns, (5) Latitude_dd.1, and (6) Latitude_dd.2. } \description{ +Create strata data frame using \code{\link{StrataAreas.fn}} +} +\details{ Create a data frame of strata formatted for use by models that need estimates of the area for each strata to expand estimates of abundance. Strata limits are provided by the user in terms of diff --git a/man/Format.AKSlope.fn.Rd b/man/Format.AKSlope.fn.Rd index 7432e0f..be27f9d 100644 --- a/man/Format.AKSlope.fn.Rd +++ b/man/Format.AKSlope.fn.Rd @@ -2,12 +2,7 @@ % Please edit documentation in R/Format.AKSlope.fn.R \name{Format.AKSlope.fn} \alias{Format.AKSlope.fn} -\title{Rename columns in the AFSC slope survey data file -received prior to the creation of the NWFSC data -warehouse. This function converts the older data files -to create the needed column names to work within survey -package functions. Output from this function will be list -of containing catch, length, and age data.} +\title{Rename AFSC slope survey columns from data pulled before 2017} \usage{ Format.AKSlope.fn( dir = NULL, @@ -37,6 +32,9 @@ survey is 1997.} warnings to the console. The default is \code{TRUE}.} } \description{ +Rename AFSC slope survey columns from data pulled before 2017 +} +\details{ Rename columns in the AFSC slope survey data file received prior to the creation of the NWFSC data warehouse. This function converts the older data files diff --git a/man/GetN.fn.Rd b/man/GetN.fn.Rd index 5ca1f76..15ae813 100644 --- a/man/GetN.fn.Rd +++ b/man/GetN.fn.Rd @@ -18,7 +18,7 @@ GetN.fn( \item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} -\item{dat}{A \code{data.frame} of composition data created using \code{\link[=pull_bio]{pull_bio()}}.} +\item{dat}{A data frame of composition data created using \code{\link[=pull_bio]{pull_bio()}}.} \item{type}{A string specifying whether doing "length" or "age" that is used to ensure the sample size is of the correct column and create @@ -43,6 +43,23 @@ warnings to the console. The default is \code{TRUE}.} } \description{ Calculate input sample sizes +} +\examples{ +\dontrun{ +bio <- pull_bio( + common_name = "petrale sole", + survey = "NWFSC.Combo" +) + +n <- GetN.fn( + dat = bio, + type = "length", + species = "flatfish" +) + +} + + } \references{ Stewart, I.J. and O.S. Hamel. 2014. diff --git a/man/GetSpp.fn.Rd b/man/GetSpp.fn.Rd index 9a97a0a..ed67adf 100644 --- a/man/GetSpp.fn.Rd +++ b/man/GetSpp.fn.Rd @@ -25,6 +25,9 @@ species values used as input in the input column; and strata used to assess its status in the strata column. } \description{ +Get Species Information +} +\details{ Get the scientific name, common name, and strata group for a vector of species. } diff --git a/man/GetSppDefault.fn.Rd b/man/GetSppDefault.fn.Rd index f2cf7a7..8b4ee32 100644 --- a/man/GetSppDefault.fn.Rd +++ b/man/GetSppDefault.fn.Rd @@ -11,6 +11,9 @@ A vector of strings specifying common names with words separated using underscores. } \description{ +Get Vector of Default Species Names for US West Coast +} +\details{ A standard list of common names for species of interest to the US West Coast. This list does not reflect ecosystem or financial importance, and instead it is strictly a list of species for which diff --git a/man/GetStrata.fn.Rd b/man/GetStrata.fn.Rd index 093eb55..b83e5cb 100644 --- a/man/GetStrata.fn.Rd +++ b/man/GetStrata.fn.Rd @@ -24,6 +24,9 @@ A data frame with six columns, \item Latitude_dd.2 (decimal degrees; northern border).} } \description{ +Get Default Strata +} +\details{ Get a data frame of strata for design-based estimates and survey composition data. Several strata are available for different default areas, as well as combinations using \code{"_"} in the argument \code{area}. diff --git a/man/GetSurveyAbb.fn.Rd b/man/GetSurveyAbb.fn.Rd index ace2cd4..0c294a0 100644 --- a/man/GetSurveyAbb.fn.Rd +++ b/man/GetSurveyAbb.fn.Rd @@ -23,6 +23,9 @@ matrix by default, but this return value for unmatched surveys can be changed by altering \code{na.return}. } \description{ +Get Survey Abbreviation +} +\details{ Get abbreviations for a vector of survey names. The input vector of names, which are typically names used to pull the data from the warehouse, do not always match the name agreed upon within the diff --git a/man/PlotBio.fn.Rd b/man/PlotBio.fn.Rd index add4138..c365a4e 100644 --- a/man/PlotBio.fn.Rd +++ b/man/PlotBio.fn.Rd @@ -26,7 +26,8 @@ If dir = NULL no output will be saved.} \item{dat}{object created by the \code{\link[=Biomasss.fn]{Biomasss.fn()}}} -\item{CI}{confidence interval} +\item{CI}{A numerical value that specifies the confidence interval to return. +Values should be between 0.01 to 0.99.} \item{scalar}{simply the divisor for the biomass} @@ -55,5 +56,5 @@ no longer have to specify \code{dopng} to save the plot as a png.} Plots the biomass with confidence intervals } \author{ -Allan Hicks and John Wallace +Chantel Wetzel, Allan Hicks, and John Wallace } diff --git a/man/PlotBioStrata.fn.Rd b/man/PlotBioStrata.fn.Rd index ebc749a..2439768 100644 --- a/man/PlotBioStrata.fn.Rd +++ b/man/PlotBioStrata.fn.Rd @@ -31,7 +31,8 @@ If dir = NULL no output will be saved.} \item{dat}{Data frame created by the \code{\link[=Biomass.fn]{Biomass.fn()}}} -\item{CI}{confidence interval} +\item{CI}{A numerical value that specifies the confidence interval to return. +Values should be between 0.01 to 0.99.} \item{scalar}{simply the divisor for the biomass} @@ -70,5 +71,5 @@ no longer have to specify \code{dopng} to save the plot as a png.} Plots the design-based biomass estimates by strata with confidence intervals } \author{ -Allan Hicks and John Wallace +Chantel Wetzel, Allan Hicks, and John Wallace } diff --git a/man/PlotFreqData.fn.Rd b/man/PlotFreqData.fn.Rd index 6ab309d..0f7c3c1 100644 --- a/man/PlotFreqData.fn.Rd +++ b/man/PlotFreqData.fn.Rd @@ -56,5 +56,5 @@ no longer have to specify \code{dopng} to save the plot as a png.} Plot length or age compositions by year in bubble plots } \author{ -Allan Hicks and Chantel Wetzel +Chantel Wetzel and Allan Hicks } diff --git a/man/PlotPresenceAbsence.fn.Rd b/man/PlotPresenceAbsence.fn.Rd index ed78b94..6cdbfa0 100644 --- a/man/PlotPresenceAbsence.fn.Rd +++ b/man/PlotPresenceAbsence.fn.Rd @@ -21,8 +21,8 @@ PlotPresenceAbsence.fn( ) } \arguments{ -\item{data}{data.frame containing data per haul created by \code{\link[=PullCatch.fn]{PullCatch.fn()}} -or biological data created by \code{\link[=PullBio.fn]{PullBio.fn()}} where the \code{dim = "sex"} must +\item{data}{Data frame containing data per haul created by \code{\link[=pull_catch]{pull_catch()}} +or biological data created by \code{\link[=pull_bio]{pull_bio()}} where the \code{dim = "sex"} must be true for the latter.} \item{dim}{Dimension of interest, either "depth", "lat", or "sex".} diff --git a/man/PlotSexRatio.fn.Rd b/man/PlotSexRatio.fn.Rd index 4c10549..1a7302e 100644 --- a/man/PlotSexRatio.fn.Rd +++ b/man/PlotSexRatio.fn.Rd @@ -15,13 +15,15 @@ PlotSexRatio.fn( ) } \arguments{ -\item{dir}{directory location for saving the png} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{data object} +\item{dat}{Data object with biological data from \code{\link[=pull_bio]{pull_bio()}} with a column +named \code{Sex} present.} -\item{data.type}{"length" or "age"} +\item{data.type}{Specify where to calculate the sex ration by length or age.} -\item{main}{ame that will be used to name the saved png} +\item{main}{Name that will be used to name the saved png} \item{circleSize}{circle size} diff --git a/man/PlotSexRatioStrata.fn.Rd b/man/PlotSexRatioStrata.fn.Rd index f8a0d4d..4041442 100644 --- a/man/PlotSexRatioStrata.fn.Rd +++ b/man/PlotSexRatioStrata.fn.Rd @@ -22,7 +22,7 @@ If dir = NULL no output will be saved.} \item{dat}{A data frame of length-composition data returned from \code{\link[=pull_bio]{pull_bio()}}.} -\item{type}{length/age which data type to use} +\item{type}{Specify where to calculate the sex ration by length or age.} \item{strat.vars}{Variables in both data frame that are used to define the stratas. Default is bottom depth (m) and latitudes (decimal diff --git a/man/ReadInAges.fn.Rd b/man/ReadInAges.fn.Rd index 7f0d173..0564f98 100644 --- a/man/ReadInAges.fn.Rd +++ b/man/ReadInAges.fn.Rd @@ -2,22 +2,28 @@ % Please edit documentation in R/ReadInAges.fn.R \name{ReadInAges.fn} \alias{ReadInAges.fn} -\title{Reads in the West Coast Trienial survey data and filters the data into what is necessary -It reads in data and makes sure only the species necessary are kept -may want to keep NA (blank in Excel) to select the zero tows -removeCAN is a flag if you want tows in Canadian waters removed} +\title{Cleans triennial survey data by year and area} \usage{ ReadInAges.fn(dat, subset_years = NULL, verbose = TRUE) } \arguments{ \item{dat}{data file name} -\item{subset_years}{specify the years to retain, default is NULL which will provide 1977, alternative input would be 1980:2002 to remove only 1977.} +\item{subset_years}{specify the years to retain, default is NULL which will +provide 1977, alternative input would be 1980:2002 to remove only 1977.} \item{verbose}{A logical that specifies if you want to print messages and warnings to the console. The default is \code{TRUE}.} } \description{ +Cleans triennial survey data by year and area +} +\details{ +Reads in the West Coast Trienial survey data and filters the data into what +is necessary. It reads in data and makes sure only the species necessary are +kept may want to keep NA (blank in Excel) to select the zero tows +removeCAN is a flag if you want tows in Canadian waters removed. + Necessary column names SPECIES_CODE AGE diff --git a/man/SexRatio.fn.Rd b/man/SexRatio.fn.Rd index 5a3cc9d..e63ce11 100644 --- a/man/SexRatio.fn.Rd +++ b/man/SexRatio.fn.Rd @@ -45,14 +45,16 @@ of the levels are documented.} warnings to the console. The default is \code{TRUE}.} } \description{ +Assign sex to unsexed fish based on fish with similar traits +} +\details{ Assign sex to fish that were sampled but not sexed based on the proportion of like fish that were female out of sexed fish. After assigning unsexed fish to males and females, new sample sizes of each sex are calculated and the expansion factors are augmented. The definition of what classifies as "like fish" depends on the stage of the expansion, see the Details section. -} -\details{ + The sex ratio is calculated as the number of females divided by the sum of the number of females and males. So, the value being reported is actually the proportion of females. diff --git a/man/SurveyAFs.fn.Rd b/man/SurveyAFs.fn.Rd index 2d30745..b23f5dc 100644 --- a/man/SurveyAFs.fn.Rd +++ b/man/SurveyAFs.fn.Rd @@ -111,6 +111,9 @@ Default TRUE.} warnings to the console. The default is \code{TRUE}.} } \description{ +Create marginal age composition data +} +\details{ Create expanded marginal age composition data based on the pre-specified strata. This function is designed to be used with catch pulled using \code{\link[=pull_catch]{pull_catch()}} and biological data pulled using \code{\link[=pull_bio]{pull_bio()}}. The default output is formatted based diff --git a/man/check_dir.Rd b/man/check_dir.Rd index 2285a6d..6b2d495 100644 --- a/man/check_dir.Rd +++ b/man/check_dir.Rd @@ -14,6 +14,9 @@ If dir = NULL no output will be saved.} warnings to the console. The default is \code{TRUE}.} } \description{ +Directory check +} +\details{ Check that \enumerate{ \item The user knows that the data will not be saved if \code{dir = NULL}. diff --git a/man/est_growth.Rd b/man/est_growth.Rd index cd713af..ec5c5fe 100644 --- a/man/est_growth.Rd +++ b/man/est_growth.Rd @@ -3,7 +3,7 @@ \name{est_growth} \alias{est_growth} \title{Estimate length-at-age using the von Bertanlaffy -parametization from Stock Synthesis.} +parametization} \usage{ est_growth( dir = NULL, @@ -18,14 +18,15 @@ est_growth( ) } \arguments{ -\item{dir}{Directory to save output.} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{The data loaded from the NWFSC database} +\item{dat}{Data frame of biological data from \code{\link[=pull_bio]{pull_bio()}}} \item{return_df}{TRUE/FALSE If set to TRUE the dat data frame is returned with added columns for the estimated Lhat_low, Lhat_pred, and Lhat_high.} -\item{Par}{Dataframe of starting parameters for K, Linf, L0, CV0, and CV2 based on the +\item{Par}{Data frame of starting parameters for K, Linf, L0, CV0, and CV2 based on the Stock Synthesis parameterization of von Bertanlaffy growth.} \item{bySex}{Logical to indicate if plot by sex} @@ -44,7 +45,7 @@ no longer have to specify \code{dopng} to save the plot as a png.} } \description{ Estimate length-at-age using the von Bertanlaffy -parametization from Stock Synthesis. +parametization } \seealso{ \code{\link[=fit_vbgrowth]{fit_vbgrowth()}} diff --git a/man/estimate_weight_length.Rd b/man/estimate_weight_length.Rd index 68a867f..4b9f800 100644 --- a/man/estimate_weight_length.Rd +++ b/man/estimate_weight_length.Rd @@ -13,18 +13,17 @@ estimate_weight_length( } \arguments{ \item{data}{A data frame containing empirical weights and lengths -from sampled fish. -Sexes should be available in the column \code{sex} or \code{SEX}.} +from sampled fish. Sexes should be available in the column \code{sex} or \code{SEX}.} \item{col_length}{A numeric or character value specifying the column to use in \code{data} for length information. These lengths are assumed to be in centimeters. The default value is \code{lengthcm}, which is added -to a data set automatically when running \link{cleanPacFIN}.} +to a data set automatically when running \code{\link[=cleanPacFIN]{cleanPacFIN()}}.} \item{col_weight}{A numeric or character value specifying the column to use in \code{data} for weight information. These weights are assumed to be in kilograms The default value is \code{weightkg}, which is added -to a data set automatically when running \link{cleanPacFIN}. +to a data set automatically when running \code{\link[=cleanPacFIN]{cleanPacFIN()}}. Using kilograms is the default because Stock Synthesis assumes the weight-length parameters are calculated using centimeters and kilograms. The reported values are easily scaled to give you results in grams if @@ -44,6 +43,9 @@ This will happen when there are no females in your data set, for example. } \description{ +Calculate weight-length relationship parameters +} +\details{ Estimate parameters of the weight-length relationship for each sex and all sexes combined, where the latter includes unsexed fish. } diff --git a/man/fit_vbgrowth.Rd b/man/fit_vbgrowth.Rd index 8c2139e..a1acbea 100644 --- a/man/fit_vbgrowth.Rd +++ b/man/fit_vbgrowth.Rd @@ -47,6 +47,9 @@ from the predicted value depends on the \code{sdFactor}, allowing confidence intervals based on normal theory or other theories to be created. } \description{ +Estimate von Bertanlaffy growth parameters from lengths and ages +} +\details{ Estimate von Bertanlaffy growth parameters from length and age data or predicted lengths given ages and input parameters. } diff --git a/man/get_json.Rd b/man/get_json.Rd index 1833ee4..0041c75 100644 --- a/man/get_json.Rd +++ b/man/get_json.Rd @@ -14,6 +14,9 @@ warehouse.} A data frame. } \description{ +Get json content from a URL +} +\details{ Get information stored on the web in .json format using a URL. The content is first pulled from the web as text with UTF-8 encoding. Then the text is passed to \code{\link[jsonlite:fromJSON]{jsonlite::fromJSON()}}. This workflow ensures that the URL diff --git a/man/plot_comps.Rd b/man/plot_comps.Rd index 3f15271..d552e04 100644 --- a/man/plot_comps.Rd +++ b/man/plot_comps.Rd @@ -17,9 +17,8 @@ plot_comps( \arguments{ \item{data}{Data file object created by \code{\link[=SurveyLF.fn]{SurveyLF.fn()}} or \code{\link[=SurveyAF.fn]{SurveyAF.fn()}}.} -\item{dir}{Directory to save files to. The default is \code{NULL}, which leads to -the figures being printed to the screen rather than saved. If a path is -provided, then the figures will only be saved, i.e., not printed.} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} \item{add_save_name}{Option to add text to a saved figure name. This option can be useful if creating plots across multiple species and saving them diff --git a/man/plot_cpue.Rd b/man/plot_cpue.Rd index 0dcdd04..2c94b97 100644 --- a/man/plot_cpue.Rd +++ b/man/plot_cpue.Rd @@ -7,9 +7,10 @@ plot_cpue(dir = NULL, catch, plot = 1:3, width = 7, height = 7) } \arguments{ -\item{dir}{Directory to save files to} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{catch}{Data catch file} +\item{catch}{Data catch file pulled using \code{\link[=pull_catch]{pull_catch()}}} \item{plot}{A vector of integers specifying the figures you want.} diff --git a/man/plot_varlenage.Rd b/man/plot_varlenage.Rd index f501d0e..62aeb98 100644 --- a/man/plot_varlenage.Rd +++ b/man/plot_varlenage.Rd @@ -19,9 +19,10 @@ plot_varlenage( ) } \arguments{ -\item{dir}{Directory to save output.} +\item{dir}{Directory where output will be saved. The directory where the file should be saved. +If dir = NULL no output will be saved.} -\item{dat}{The data loaded from the NWFSC database} +\item{dat}{The data loaded from \code{\link[=pull_bio]{pull_bio()}}} \item{main}{Name that will be used to name the saved png} @@ -48,7 +49,11 @@ no longer have to specify \code{dopng} to save the plot as a png.} \item{...}{Additional arguments for the plots.} } \description{ -Plots the SD and CV of age at observed and predicted length +Plot variability of length at age +} +\details{ +Plots the standard deviation and coefficient of variation of age at observed +and predicted length } \author{ Chantel Wetzel diff --git a/man/pull_bio.Rd b/man/pull_bio.Rd index 57e1a63..ae04b6a 100644 --- a/man/pull_bio.Rd +++ b/man/pull_bio.Rd @@ -2,10 +2,7 @@ % Please edit documentation in R/pull_bio.R \name{pull_bio} \alias{pull_bio} -\title{Pull biological data (age, length, weight) from the NWFSC data warehouse -The website is: https://www.webapps.nwfsc.noaa.gov/data -This function can be used to pull a single species or all observed species -In order to pull all species leave common_name or sci_name as NULL} +\title{Pull biological data (age, length, weight) from the NWFSC data warehouse} \usage{ pull_bio( common_name = NULL, @@ -81,7 +78,6 @@ which aligns with the expected names in data processing functions.} warnings to the console. The default is \code{TRUE}.} } \description{ -Pull biological data (age, length, weight) from the NWFSC data warehouse The website is: https://www.webapps.nwfsc.noaa.gov/data This function can be used to pull a single species or all observed species In order to pull all species leave common_name or sci_name as NULL diff --git a/man/pull_gemm.Rd b/man/pull_gemm.Rd index 8d72d1b..63b8628 100644 --- a/man/pull_gemm.Rd +++ b/man/pull_gemm.Rd @@ -2,17 +2,9 @@ % Please edit documentation in R/pull_gemm.R \name{pull_gemm} \alias{pull_gemm} -\title{Pull gemm data from the NWFSC data warehouse -The website is: https://www.webapps.nwfsc.noaa.gov/data -This function can be used to pull all gemm data, a single species, or a -subset of species c("Canary Rockfish", "Widow Rockfish"). Species names in -the gemm are capitalized (e.g. Canary Rockfish). However, there are checks in -the function to adjust input species names if the input names do not match -the expected capitalization (e.g. "canary rockfish", "canary_rockfish"). The -fuction also allows you to subset the data by year using the years input and to -save the object if the dir function input is given.} +\title{Pull gemm data from the NWFSC data warehouse} \usage{ -pull_gemm(common_name, years, dir) +pull_gemm(common_name, years, dir = NULL, verbose = TRUE) } \arguments{ \item{common_name}{A character entry with the desired common name of the @@ -28,9 +20,11 @@ Vector can not contain -Inf or Inf.} \item{dir}{Directory where output will be saved. The directory where the file should be saved. If dir = NULL no output will be saved.} + +\item{verbose}{A logical that specifies if you want to print messages and +warnings to the console. The default is \code{TRUE}.} } \description{ -Pull gemm data from the NWFSC data warehouse The website is: https://www.webapps.nwfsc.noaa.gov/data This function can be used to pull all gemm data, a single species, or a subset of species c("Canary Rockfish", "Widow Rockfish"). Species names in @@ -45,8 +39,8 @@ save the object if the dir function input is given. # Pull all GEMM data all_data <- pull_gemm() -# Pull for a specific specis -widow_data <- pull_gemm(common_name = "Widow Rockfish") +# Pull for a specific specis +widow_data <- pull_gemm(common_name = "widow rockfish") # Pull multiple species data <- pull_gemm(common_name = c("Widow Rockfish", "Canary Rockfish")) diff --git a/man/pull_haul.Rd b/man/pull_haul.Rd index 6cb679e..2e25ccf 100644 --- a/man/pull_haul.Rd +++ b/man/pull_haul.Rd @@ -2,9 +2,7 @@ % Please edit documentation in R/pull_haul.R \name{pull_haul} \alias{pull_haul} -\title{Pull haul data from the NWFSC data warehouse. -The website is: https://www.webapps.nwfsc.noaa.gov/data. -This function can be used to pull haul data and associated covariates.} +\title{Pull haul data from the NWFSC data warehouse.} \usage{ pull_haul(years = c(1970, 2050), survey, dir = NULL, verbose = TRUE) } @@ -58,7 +56,6 @@ warnings to the console. The default is \code{TRUE}.} Returns a data frame of haul characteristics for satisfactory hauls } \description{ -Pull haul data from the NWFSC data warehouse. The website is: https://www.webapps.nwfsc.noaa.gov/data. This function can be used to pull haul data and associated covariates. }