Skip to content

Commit

Permalink
Merge pull request #33 from pfmc-assessments/style-doc-code
Browse files Browse the repository at this point in the history
I changed the github workflow that updated documentation with one that does all that as well as style the code (as discussed in nmfs-fish-tools/ghactions4r#131). So now we have nicely styled code.
  • Loading branch information
iantaylor-NOAA authored Jul 12, 2024
2 parents 10eddd1 + 8ba9e0e commit 0f1186f
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 228 deletions.
137 changes: 44 additions & 93 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,53 @@ Package: PEPtools
Title: Tools for Stock Assessments used by the Population Ecology Program
Version: 0.0.2.0001
Authors@R: c(
person(
given = c("Kelli", "F."),
family = "Johnson",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-5149-451X")
),
person(
given = c("Ian", "G."),
family = "Taylor",
role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0000-0002-4232-5669")
),
person(
given = c("Chantel", "R."),
family = "Wetzel",
role = "aut",
email = "[email protected]",
comment = c(ORCID = "0000-0002-7573-8240")
),
person(
given = c("John", "R."),
family = "Wallace",
role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0000-0002-2333-1262")
),
person(
given = c("Kiva"),
family = "Oken",
role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0000-0002-5627-6837")
),
person(
given = c("Kristin", "N."),
family = "Marshall",
role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0000-0002-9769-2300")
),
person(
given = c("Edward", "J."),
family = "Dick",
role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0000-0001-7681-9176")
),
person(
given = c("Melissa"),
family = "Monk",
role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0009-0007-6407-5131")
),
person(
given = c("Jason"),
family = "Cope",
role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0000-0001-7812-6728")
),
person(
given = c("Brian", "J."),
family = "Langseth",
role = "ctb",
email = "[email protected]",
comment = c(ORCID = "0000-0002-9901-6146")
)
)
Description: The package contains various tools that are useful to
scientists at the Northwest Fisheries Science Center (NWFSC)
in the Population Ecology Program (PEP). Users typically spend the
majority of their time producing assessments of groundfish stock off the
U.S. West Coast. Though, many of the tools will also be useful for
the general science they conduct as well.
Depends: R (>= 3.5.0)
person(c("Kelli", "F."), "Johnson", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-5149-451X")),
person(c("Ian", "G."), "Taylor", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-4232-5669")),
person(c("Chantel", "R."), "Wetzel", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-7573-8240")),
person(c("John", "R."), "Wallace", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-2333-1262")),
person("Kiva", "Oken", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-5627-6837")),
person(c("Kristin", "N."), "Marshall", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-9769-2300")),
person(c("Edward", "J."), "Dick", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0001-7681-9176")),
person("Melissa", "Monk", , "[email protected]", role = "ctb",
comment = c(ORCID = "0009-0007-6407-5131")),
person("Jason", "Cope", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0001-7812-6728")),
person(c("Brian", "J."), "Langseth", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-9901-6146"))
)
Description: The package contains various tools that are useful to
scientists at the Northwest Fisheries Science Center (NWFSC) in the
Population Ecology Program (PEP). Users typically spend the majority
of their time producing assessments of groundfish stock off the U.S.
West Coast. Though, many of the tools will also be useful for the
general science they conduct as well.
License: MIT + file LICENSE
Depends:
R (>= 3.5.0)
Imports:
adnuts,
glue,
lubridate,
pkgbuild,
r4ss,
remotes,
stats,
usethis,
utils
adnuts,
glue,
lubridate,
pkgbuild,
r4ss,
remotes,
stats,
usethis,
utils
Suggests:
devtools,
TMB
devtools,
TMB
Remotes:
github::cole-monnahan-noaa/adnuts,
github::r4ss/r4ss
License: MIT + file LICENSE
github::cole-monnahan-noaa/adnuts,
github::r4ss/r4ss
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
2 changes: 1 addition & 1 deletion R/PEPmeeting.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' PEPtools::PEPmeeting()
PEPmeeting <- function(year = format(Sys.time(), "%Y"),
people = c(
"Aaron", "Brian", "Chantel", "Ian", "Jason",
"Aaron", "Brian", "Chantel", "Ian", "Jason",
"John", "Kelli", "Kiva", "Kristin", "Vlada"
)) {
set.seed(year)
Expand Down
66 changes: 32 additions & 34 deletions R/buffer_fxn.R
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
#' Buffer calculation for West Coast groundish assessments
#'
#' @details
#'
#' @details
#' Buffer calculation for U.S. West Coast Groundfish Stocks
#' Applies the time-varying sigma approach based on the 2019
#' approach described in:
#' approach described in:
#' Wetzel, C.R. and O.S. Hamel, 2023. Applying a probability harvest control rule
#' to account for increased uncertainty in setting precautionary harvest limits
#' from past stock assessments. Fisheries Research 262: 106659.
#'
#' from past stock assessments. Fisheries Research 262: 106659.
#'
#' @param years Years to generate buffer values. The first year should align with
#' the year of the assessment. Input should be vector of years to calulculate
#' West Coast groundfish buffers for (e.g., years = 2021:2032).
#' @param sigma The initial sigma value to use based on West Coast groundfish
#' assessment categories (cat 1 = 0.50, cat 2 = 1.0, cat 3 = 2.0). For categories
#' 1 and 2 the sigma will be time-varying.
#' 1 and 2 the sigma will be time-varying.
#' @param pstar The management risk tolerance determined by the PFMC (i.e., 0.45, 0.40).
#'
#'
#' @examples
#' get_buffer(years = 2011:2032, sigma = 1.0, pstar = 0.4)
#' @author written by Chantel Wetzel
#' @export
#'
get_buffer <- function(years, sigma, pstar){

y <- 1:(length(years) - 1)
if (sigma != 2.0) {
# the rate of change in sigma approved by the SSC in 2019
r <- 0.075
} else {
get_buffer <- function(years, sigma, pstar) {
y <- 1:(length(years) - 1)
if (sigma != 2.0) {
# the rate of change in sigma approved by the SSC in 2019
r <- 0.075
} else {
r <- 0
}

# This is the equation for the rate of change in sigma
sigma_calc <- c(sigma, sigma * (1+(y-1)*r))
buffer <- exp(stats::qnorm(pstar, 0, sigma_calc))
max_buffer <- exp(stats::qnorm(pstar, 0, 2.0))
# Set the buffer for fixed catch years to 1.0
buffer[1:2] <- 1
category_3 <- which(buffer < max_buffer)
if (length(category_3) > 0) {
buffer[category_3] <- max_buffer
}

out <- data.frame(
year = years,
buffer = round(buffer, 3)
)

return(out)
}
}

# This is the equation for the rate of change in sigma
sigma_calc <- c(sigma, sigma * (1 + (y - 1) * r))
buffer <- exp(stats::qnorm(pstar, 0, sigma_calc))
max_buffer <- exp(stats::qnorm(pstar, 0, 2.0))
# Set the buffer for fixed catch years to 1.0
buffer[1:2] <- 1
category_3 <- which(buffer < max_buffer)
if (length(category_3) > 0) {
buffer[category_3] <- max_buffer
}

out <- data.frame(
year = years,
buffer = round(buffer, 3)
)

return(out)
}
3 changes: 1 addition & 2 deletions R/check_filename.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
#' check_filename(tempdir())
#'
check_filename <- function(paths) {

# Check for spaces
stopifnot(all(!grepl("\\s", paths)))

return(paths)
}
}
12 changes: 8 additions & 4 deletions R/check_install_TMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ check_install_TMB <- function() {
stopifnot(pkgbuild::find_rtools())
packages <- utils::installed.packages()
if (!"TMB" %in% packages[, "Package"]) {
stop("Use the following code to install TMB\n",
"install.packages('TMB')")
stop(
"Use the following code to install TMB\n",
"install.packages('TMB')"
)
}
if (!"TMBhelper" %in% packages[, "Package"]) {
stop("Use the following code to install TMBhelper\n",
"remotes::install_github('kaskr/TMB_contrib_R/TMBhelper')")
stop(
"Use the following code to install TMBhelper\n",
"remotes::install_github('kaskr/TMB_contrib_R/TMBhelper')"
)
}

wd <- getwd()
Expand Down
Loading

0 comments on commit 0f1186f

Please sign in to comment.