Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation updates #69

Merged
merged 18 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ inst/doc
#folder
testing
docs
other
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ RoxygenNote: 7.3.1
Suggests:
knitr,
rmarkdown,
markdown
markdown,
kableExtra
VignetteBuilder: knitr
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export(get_survdat_scallop_data)
export(get_vessel)
export(plot_data_area)
export(plot_shapefile)
export(post_strat)
export(strat_mean)
export(strat_prep)
export(swept_area)
importFrom(data.table,"%like%")
importFrom(data.table,"key")
importFrom(magrittr,"%>%")
8 changes: 4 additions & 4 deletions R/apply_conversion_factors.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#' This is an internal function.
#' To pull the values of the conversion factors use \code{\link{get_conversion_factors}}
#'
#'@noRd



Expand All @@ -30,10 +31,9 @@ apply_conversion_factors <- function(channel,survdat.raw,use.SAD = F) {
survdat[, ABUNDANCE := as.double(ABUNDANCE)]

#Grab all conversion factors off the network
convert.qry <- "select *
from svdbs.survan_conversion_factors"

convert <- data.table::as.data.table(DBI::dbGetQuery(channel, convert.qry))
conversionFactors <- get_conversion_factors(channel)
convert.qry <- conversionFactors$sql
convert <- data.table::as.data.table(conversionFactors$data)

#DCF < 1985 Door Conversion
dcf.spp <- convert[DCF_WT > 0, SVSPP]
Expand Down
20 changes: 16 additions & 4 deletions R/calc_stratified_mean.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@
#'
#' Calculates the stratified mean. Details of method found here ...
#'
#' @inheritParams strat_prep
#' @inheritParams strat_mean
#' @param surveyData Data table. NEFSC survey data generated by \code{get_survdat_data.R}
#' @param areaPolygon sf object or character string. Default = "NEFSC strata". The default option uses the survey strata shapefile bundled with the package.
#' To use any other shapefile for stratification, the shapefile must be read in as an \link[sf]{sf} object and the \code{areaDescription} argument must be specified.
#' @param areaDescription Character String. Column name from \code{areaPolygon}
#' that contains the strata designations.
#' @param filterByArea Numeric vector. Set of areas to subset from the
#' \code{areaDescription} of the \code{areaPolygon}.
#' @param filterBySeason Character string. Which seasons of the \code{surveyData}
#' should be included. Choices include "SPRING", "FALL", or "all".
#' @param groupDescription Character string. Column of \code{prepData} which
#' contains the groups (e.g. "SVSPP") on which the means are based.
#' @param filterByGroup Character or numeric vector. Set of groups to subset from
#' \code{groupDescription}. The default "all" will calculate means for all groups.
#' @param mergesexFlag Boolean. Logical value to merge sexed species such as dogfish.
#' @param tidy Boolean. Return output in long format (Default = F).
#' @param returnPrepData Boolean. Return both \code{stratmeanData} and \code{prepData}
#' as a list object. The default (F) returns only the \code{stratmeanData} as a
Expand Down Expand Up @@ -58,15 +70,15 @@ calc_stratified_mean <- function(surveyData, areaPolygon = 'NEFSC strata',

#Run stratification prep
message("Prepping data ...")
prepData <- survdat::strat_prep(surveyData, areaPolygon, areaDescription,
prepData <- survdat:::strat_prep(surveyData, areaPolygon, areaDescription,
filterByArea, filterBySeason)

#Calculate stratified mean
message("Calculating Stratified Mean ...")
#Check if calculating mean base on all station or by season
if(filterBySeason[1] == "all"){seasonFlag <- F}else{seasonFlag <- T}

stratmeanData <- survdat::strat_mean(prepData, groupDescription, filterByGroup,
stratmeanData <- survdat:::strat_mean(prepData, groupDescription, filterByGroup,
mergesexFlag, seasonFlag = seasonFlag,
areaDescription, poststratFlag)

Expand Down
2 changes: 1 addition & 1 deletion R/calc_swept_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ calc_swept_area <- function(surveyData, areaPolygon = 'NEFSC strata',

#Calculate total biomass/abundance estimates
message("Calculating Swept Area Estimate ...")
sweptareaData <- survdat::swept_area(prepData = stratmeanData$prepData,
sweptareaData <- survdat:::swept_area(prepData = stratmeanData$prepData,
stratmeanData = stratmeanData$stratmeanData,
q = q, areaDescription = areaDescription,
groupDescription = groupDescription)
Expand Down
2 changes: 1 addition & 1 deletion R/get_conversion_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
get_conversion_factors <- function(channel){

# creates the sql based on user input
sqlStatement <- convert.qry <- "select * from SURVAN_CONVERSION_FACTORS"
sqlStatement <- convert.qry <- "select * from SVDBS.SURVAN_CONVERSION_FACTORS"

query <- DBI::dbGetQuery(channel,sqlStatement)

Expand Down
7 changes: 4 additions & 3 deletions R/get_length_weight.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#'Generate a table of length weight coefficients
#' Extract species specific LENGTH-WEIGHT COEFFICIENTS from SVDBS
#'
#'Pulls the length-weight coefficients calculated from NOAA Tech Memo NMFS-NE-171.
#'Pulls the length-weight coefficients from SVDBS LENGTH_WEIGHT_COEFFICIENTS table
#' These coefficients are described in NOAA Tech Memo NMFS-NE-171.
#'
#'
#' @inheritParams get_survdat_data
Expand All @@ -11,7 +12,7 @@
#'\item{SVLWEXP}{The exponent of the length-weight equation, b.}
#'\item{SVLWCOEFF}{The natural log of the coefficient of the length-weight equation, ln a.}
#'
#'@family survdat
#'@family helper
#'
#'@export

Expand Down
31 changes: 19 additions & 12 deletions R/get_survdat_data.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
#' Extracts Survey data from Database
#' Extracts Survey data from Database
#'
#'Connects to svdbs and pulls data from MSTR_CRUISE, UNION_FSCS_SVCAT, UNION_FSCS_SVLEN, UNION_FSCS_SVSTA, UNION_FSCS_SVBIO
#' Connects to svdbs and pulls data from MSTR_CRUISE, UNION_FSCS_SVCAT,
#' UNION_FSCS_SVLEN, UNION_FSCS_SVSTA, UNION_FSCS_SVBIO
#'
#' @param channel an Object inherited from \link[DBI]{DBIConnection-class}. This object is used to communicate with the database engine. (see \code{\link[dbutils]{connect_to_database}})
#' @param channel an Object inherited from \link[DBI]{DBIConnection-class}.
#' This object is used to communicate with the database engine.
#' (see \code{\link[dbutils]{connect_to_database}})
#' @param filterByYear Numeric vector. Subset of years from which to pull data.
#' If not specified then all years are pulled. (Default = NA)
#' @param all.season Boolean. Spring and Fall only (F) otherwise T. (Default = F)
#' @param shg.check Boolean. use only SHG <=136 or TOGA <= 1324 (>2008). (Default = T)
#' @param conversion.factor Boolean. Whether to apply conversion factors to the data pull, (Default = T)
#' @param use.SAD Boolean. Use Survey Analysis Database (SAD) for assessed species. (Default = F)
#' @param getBio Boolean. Include biology data for each fish weight, sex,, stomach weight, stomach volume, age, maturity
#' @param getBio Boolean. Include biology data for each fish weight, sex,
#' stomach weight, stomach volume, age, maturity
#' @param getLengths Boolean. Include length data which includes the length in
#' cm and the number at length. (Default = T)
#' @param getWeightLength Boolean. Include the weight at length by applying length
#' weight coefficients from SVDBS. (Default = F)
#'
#' @return A list containing a Data frame (data.table) (n x 21), a list of SQL queries used to pull the data,
#' the date of the pull, and the call expression
#' Each row of the data.table represents the number at length of a species on a specific tow along with physical attributes of the tow.
#' @return A list containing a Data frame (data.table) (n x 21),
#' a list of SQL queries used to pull the data, the date of the pull,
#' and the call expression. Each row of the data.table represents the number
#' at length of a species on a specific tow along with physical attributes of the tow.
#'
#' The data frame (Descriptions taken from NEFSC Data dictionary)
#'
Expand Down Expand Up @@ -65,15 +70,14 @@
#'
#' The date:
#'
#' \item{pullDate}{The date the data was pulled from the database}
#' \item{pullDate}{The date the data was pulled from the database}
#'
#' The expression:
#'
#' \item{functionCall}{The call used to create the data pul}
#' \item{functionCall}{The call used to create the data pull}
#'
#' @importFrom data.table "%like%"
#'
#'@family survdat
#' @family survdat
#'
#'@examples
#'\dontrun{
Expand All @@ -89,11 +93,14 @@
#'
#'@export


get_survdat_data <- function(channel, filterByYear = NA, all.season = F,
shg.check = T, conversion.factor = T, use.SAD = F,
getBio = F, getLengths = T, getWeightLength = F) {

call <- capture_function_call()
version <- packageVersion("survdat")


# Cruise List --------------------------------------------------------------
#Generate cruise list
Expand Down Expand Up @@ -288,6 +295,6 @@ get_survdat_data <- function(channel, filterByYear = NA, all.season = F,



return(list(survdat=survdat,sql=sql,pullDate=date(),functionCall = call))
return(list(survdat=survdat,sql=sql,pullDate=date(),functionCall = call,version=version))

}
10 changes: 6 additions & 4 deletions R/get_survdat_scallop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#' @param filterByYear Numeric vector. Subset of years from which to pull data.
#' If not specified then all years are pulled. (Default = NA)
#' @param shg.check Boolean. use only SHG <=136 or TOGA <= 1324 (>2008). (Default = T)
#' @param conversion.factor Boolean. Whether to apply conversion factors to the data pull, (Default = T)
#' @param getBio Boolean. Include biology data for each fish weight, sex,, stomach weight, stomach volume, age, maturity
#' @param getLengths Boolean. Include length data which includes the length in
#' cm and the number at length. (Default = T)
#' @param getWeightLength Boolean. Include the weight at length by applying length
Expand Down Expand Up @@ -88,8 +86,12 @@
#'
#'@export

get_survdat_scallop_data <- function(channel, filterByYear = NA, shg.check = T,
getLengths = T, getWeightLength = F, scallopOnly = T){
get_survdat_scallop_data <- function(channel,
filterByYear = NA,
shg.check = T,
getLengths = T,
getWeightLength = F,
scallopOnly = T){

call <- capture_function_call()

Expand Down
2 changes: 1 addition & 1 deletion R/post_strat.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#'
#'@family survdat
#'
#' @export
#' @noRd


post_strat <- function (surveyData, areaPolygon, areaDescription, na.keep = F) {
Expand Down
10 changes: 5 additions & 5 deletions R/strat_mean.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
#'
#' @importFrom data.table "key"
#'
#'@family survdat
#'@family surdat
#'
#'@examples
#'\dontrun{
#' # Called internally
#'}
#'
#' @export
#' @noRd


strat_mean <- function (prepData, groupDescription = "SVSPP", filterByGroup = "all",
Expand All @@ -44,7 +44,7 @@ strat_mean <- function (prepData, groupDescription = "SVSPP", filterByGroup = "a
stratmeanData <- unique(stratmeanData, by = key(stratmeanData))
stratmeanData[, c('LENGTH', 'NUMLEN') := NULL]
}

data.table::setnames(stratmeanData, c(groupDescription, areaDescription),
c('group', 'strat'))

Expand Down Expand Up @@ -145,9 +145,9 @@ strat_mean <- function (prepData, groupDescription = "SVSPP", filterByGroup = "a
stratmeanData[, glen := NULL]
data.table::setkey(stratmeanData, YEAR, SVSPP, CATCHSEX)
}

if(seasonFlag == F) stratmeanData[, SEASON := 'ALL']

data.table::setnames(stratmeanData, 'group', groupDescription)

return(stratmeanData[])
Expand Down
4 changes: 2 additions & 2 deletions R/strat_prep.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' # Called internally
#' }
#'
#' @export
#' @noRd


strat_prep <- function (surveyData, areaPolygon = "NEFSC strata",
Expand All @@ -53,7 +53,7 @@ strat_prep <- function (surveyData, areaPolygon = "NEFSC strata",
# post stratify if necessary
if(poststratFlag){
message("Post stratifying ...")
surveyData <- survdat::post_strat(surveyData, areaPolygon, areaDescription)
surveyData <- survdat:::post_strat(surveyData, areaPolygon, areaDescription)
} else {
#Add extra column to original data to mimic what happens when post-stratifying
surveyData <- surveyData[, areaDescription := STRATUM]
Expand Down
2 changes: 1 addition & 1 deletion R/swept_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#'# Called internally
#'}
#'
#'@export
#'@noRd


swept_area <- function (prepData, stratmeanData, q = NULL, a = 0.0384,
Expand Down
31 changes: 0 additions & 31 deletions man/apply_conversion_factors.Rd

This file was deleted.

6 changes: 1 addition & 5 deletions man/calc_stratified_mean.Rd

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

6 changes: 1 addition & 5 deletions man/calc_swept_area.Rd

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

6 changes: 1 addition & 5 deletions man/get_area.Rd

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

1 change: 1 addition & 0 deletions man/get_conversion_factors.Rd

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

1 change: 1 addition & 0 deletions man/get_cruise_purpose.Rd

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

Loading
Loading