Skip to content
Merged

Dev #42

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
49 changes: 49 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_dispatch:

name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
54 changes: 32 additions & 22 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,58 +1,68 @@
Package: NEesp2
Title: Generates ESP Reports for the Northeast
Version: 0.1.1
Description: Generates indicators, visualizations, and reports for NEFSC Ecosystem and Socioeconomic Profiles.
License: file LICENSE
Authors@R: c(person("Abigail", "Tyrell", email = "abigail.tyrell@noaa.gov", role = c("aut", "cre"),
Authors@R: c(
person("Abigail", "Tyrell", , "abigail.tyrell@noaa.gov", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6656-8470")),
person("Stephanie", "Owen", email = "stephanie.owen@noaa.gov", role = "aut"))
person("Stephanie", "Owen", , "stephanie.owen@noaa.gov", role = "aut")
)
Maintainer: Abigail Tyrell <abigail.tyrell@noaa.gov>
Description: Generates indicators, visualizations, and reports for NEFSC
Ecosystem and Socioeconomic Profiles.
License: file LICENSE
URL: https://nefsc.github.io/READ-EDAB-NEesp2/
BugReports: https://github.com/NEFSC/READ-EDAB-NEesp2/issues
Depends:
R (>= 3.5.0)
Imports:
magrittr,
rlang
Suggests:
assessmentdata,
bookdown,
deps,
devtools,
dplyr,
DT,
ecodata,
EDABUtilities,
flextable,
FSA,
ggnewscale,
ggplot2,
ggpubr,
ggrepel,
ggridges,
ggthemes,
here,
knitr,
magrittr,
lintr,
lwgeom,
nmfspalette,
rlang,
pander,
papeR,
priceR,
rmarkdown,
scales,
sf,
stringr,
tibble,
survdat,
testthat (>= 3.0.0),
tibble,
tidyquant,
tidyr,
utils,
viridis,
assessmentdata,
FSA,
ggrepel,
pander,
papeR,
priceR,
testthat (>= 3.0.0),
lintr
viridis
VignetteBuilder:
rmarkdown
Remotes:
NEFSC/READ_EDAB_Utilities,
nmfs-general-modeling-tools/nmfspalette,
NOAA-EDAB/assessmentdata,
NOAA-EDAB/ecodata,
NOAA-EDAB/assessmentdata
VignetteBuilder:
knitr
NOAA-EDAB/survdat
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
Depends:
R (>= 3.5.0)
Config/testthat/edition: 3
RoxygenNote: 7.3.2
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Generated by roxygen2: do not edit by hand

export(add_fig_paths)
export(create_chl)
export(create_coldpool_extent)
export(create_coldpool_index)
export(create_coldpool_persistence)
export(create_gsi)
export(create_mrip_trips)
export(create_prop_sp_trips)
export(create_spatial_indicator)
export(create_sst)
export(create_template)
export(create_total_mrip)
export(create_wcr)
Expand Down
90 changes: 67 additions & 23 deletions R/create_condition_indicator.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,32 @@
#' @param by_EPU logical. If TRUE, calculates condition by EPUs specified in the input data, if FALSE, calculates condition for all data combined.
#' @param by_sex logical. If TRUE, calculates condition by sex. If FALSE, calculates condition across sexes.
#' @param length_break numeric vector. If not NULL, will calculate condition by length breaks specified in the vector. User must specify minimum and maximum lengths in this parameter, e.g., c(0, 20, 70). If NULL, will not calculate by length groupings.
#' @param more_than_20_years logical. If TRUE, only returns species with 20 or more years of data.
#' @param record_outliers logical. If TRUE, returns a list with two data frames: the first is the condition data frame, the second is a data frame of outliers that were removed from the analysis. If FALSE, only returns the condition data frame.
#' @param output character. If "soe", returns a data frame of species condition for the State of the Ecosystem report. If "esp", returns a data frame for ESPs. If "full", returns a data frame of all calculated values. *Setting by_sex = TRUE or length_break to any value will always return a full dataframe*
#' @importFrom magrittr %>%
#' @return Returns a data frame of species condition
#' @export

species_condition <- function(data,
LWparams = NEesp2::LWparams,
species.codes = NEesp2::species.codes,
by_EPU = TRUE,
by_sex = FALSE,
length_break = NULL,
output = "soe") {
if (by_sex |
!is.null(length_break)) {
species_condition <- function(
data,
LWparams = NEesp2::LWparams,
species.codes = NEesp2::species.codes,
by_EPU = TRUE,
by_sex = FALSE,
length_break = NULL,
more_than_20_years = TRUE,
record_outliers = FALSE,
output = "soe"
) {
if (
by_sex |
!is.null(length_break)
) {
if (output != "full") {
message("You asked to group results by sex and/or length ; data will not be formatted for SOE or ESP output.")
message(
"You asked to group results by sex and/or length ; data will not be formatted for SOE or ESP output."
)
}
output <- "full"
}
Expand Down Expand Up @@ -71,18 +81,24 @@ species_condition <- function(data,

# Add SEX for Combined gender back into Wigley at all data (loses 4 Gender==Unsexed):
LWpar_sexed <- new_dat |>
dplyr::mutate(sex = dplyr::case_when(
Gender == "Combined" | Gender == "Unsexed" ~ as.character(0),
Gender == "Male" ~ as.character(1),
Gender == "Female" ~ as.character(2),
TRUE ~ NA
))
dplyr::mutate(
sex = dplyr::case_when(
Gender == "Combined" | Gender == "Unsexed" ~ as.character(0),
Gender == "Male" ~ as.character(1),
Gender == "Female" ~ as.character(2),
TRUE ~ NA
)
)

LWpar_spp <- LWpar_sexed %>%
dplyr::mutate(SVSPP = as.numeric(LW_SVSPP))

# Join survdat data with LW data
mergedata <- dplyr::left_join(fall, LWpar_spp, by = c("SEASON", "SVSPP", "sex"))
mergedata <- dplyr::left_join(
fall,
LWpar_spp,
by = c("SEASON", "SVSPP", "sex")
)

# filters out values without losing rows with NAs:
mergewt <- dplyr::filter(mergedata, is.na(INDWT) | INDWT < 900)
Expand All @@ -102,7 +118,8 @@ species_condition <- function(data,
###########################################
### Calculate species condition ###

condcalc <- dplyr::mutate(mergeLW,
condcalc <- dplyr::mutate(
mergeLW,
predwt = (exp(lna)) * LENGTH^b,
RelCond = INDWT / predwt
) |>
Expand All @@ -111,7 +128,23 @@ species_condition <- function(data,
dplyr::mutate(mean = mean(RelCond), sd = sd(RelCond)) |>
dplyr::ungroup() |>
# might want to update this outlier removal eventually
dplyr::filter(RelCond < (mean + (2 * sd)) & RelCond > (mean - (2 * sd))) |>
dplyr::mutate(
outlier = RelCond > (mean + (2 * sd)) | RelCond < (mean - (2 * sd))
)

message(paste0(
"Removing ",
sum(condcalc$outlier, na.rm = TRUE),
" outliers from the data set."
))

if (record_outliers) {
outliers <- condcalc |>
dplyr::filter(outlier == TRUE)
}

condcalc <- condcalc |>
dplyr::filter(outlier == FALSE) |>
dplyr::filter(is.na(sex) | sex != 4) %>%
dplyr::mutate(sexMF = sex)

Expand Down Expand Up @@ -145,11 +178,18 @@ species_condition <- function(data,
# select columns
dplyr::select(dplyr::all_of(c(grouping_vars, "MeanCond", "nCond"))) |>
# group again, without YEAR
dplyr::group_by(!!!rlang::syms(grouping_vars[-which(grouping_vars == "YEAR")])) |>
dplyr::group_by(
!!!rlang::syms(grouping_vars[-which(grouping_vars == "YEAR")])
) |>
# filter to only species with 20+ years of data
dplyr::mutate(n = dplyr::n()) |>
dplyr::filter(n >= 20) |>
dplyr::select(-n) |>
dplyr::mutate(n = dplyr::n())

if (more_than_20_years) {
condition <- condition |>
dplyr::filter(n >= 20) |>
dplyr::select(-n)
}
condition <- condition |>
# calculate sd and variance across years
dplyr::mutate(
sd = sd(MeanCond, na.rm = TRUE),
Expand All @@ -174,5 +214,9 @@ species_condition <- function(data,
dplyr::select(Species, EPU, YEAR, MeanCond, INDICATOR_NAME) |>
dplyr::rename(DATA_VALUE = MeanCond)
}

if (record_outliers) {
condition <- list(condition = condition, outliers = outliers)
}
return(condition)
}
10 changes: 10 additions & 0 deletions R/create_recreational_indicators.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ create_total_mrip <- function(
DATA_VALUE = total_rec_catch$data_value |>
stringr::str_remove_all(",") |>
as.numeric(),
LOWER_95_CI = total_rec_catch |>
dplyr::select(dplyr::contains("LOWER")) |>
dplyr::pull() |>
stringr::str_remove_all(",") |>
as.numeric(),
UPPER_95_CI = total_rec_catch |>
dplyr::select(dplyr::contains("UPPER")) |>
dplyr::pull() |>
stringr::str_remove_all(",") |>
as.numeric(),
CATEGORY = "Recreational",
INDICATOR_TYPE = "Socioeconomic",
INDICATOR_NAME = paste0("total_recreational_", var_name, "_", var_units),
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ files <- list.files(recursive = TRUE, all.files = TRUE) %>%
stringr::str_subset(pattern = ".Renviron", negate = TRUE)
total_size <- (sum(file.size(files))/1073741824) %>%
stringr::str_trunc(width = 4, ellipsis = "")

cat(badger::badge_devel("NEFSC/READ-EDAB-NEesp2", "blue"),
badger::badge_last_commit("NEFSC/READ-EDAB-NEesp2"),
badger::badge_custom("repo size", paste(total_size, "GB"), color = "blue", url = "https://github.com/NEFSC/READ-EDAB-NEesp2"),
sep = "\n")
```
[![](https://github.com/NEFSC/READ-EDAB-NEesp2/workflows/gitleaks/badge.svg)](https://github.com/NEFSC/READ-EDAB-NEesp2/actions/workflows/secretScan.yml)
[![R-CMD-check](https://github.com/NEFSC/READ-EDAB-NEesp2/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/NEFSC/READ-EDAB-NEesp2/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

# Ecosystem and Socioeconomic Profiles
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

[![](https://img.shields.io/badge/devel%20version-0.1.1-blue.svg)](https://github.com/NEFSC/READ-EDAB-NEesp2)
[![](https://img.shields.io/github/last-commit/NEFSC/READ-EDAB-NEesp2.svg)](https://github.com/NEFSC/READ-EDAB-NEesp2/commits/main)
[![](https://img.shields.io/badge/repo%20size-1.25%20GB-blue.svg)](https://github.com/NEFSC/READ-EDAB-NEesp2)
[![](https://img.shields.io/badge/repo%20size-0.60%20GB-blue.svg)](https://github.com/NEFSC/READ-EDAB-NEesp2)
[![](https://github.com/NEFSC/READ-EDAB-NEesp2/workflows/gitleaks/badge.svg)](https://github.com/NEFSC/READ-EDAB-NEesp2/actions/workflows/secretScan.yml)
[![R-CMD-check](https://github.com/NEFSC/READ-EDAB-NEesp2/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/NEFSC/READ-EDAB-NEesp2/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

# Ecosystem and Socioeconomic Profiles
Expand Down Expand Up @@ -72,14 +73,14 @@ templates will be added shortly.
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="header">
<tr>
<th><a href="https://github.com/atyrell3">atyrell3</a></th>
<th><a href="https://github.com/stephanie-owen">stephanie-owen</a></th>
<th></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<tr>
<td><a href="https://github.com/atyrell3"><img
src="https://avatars.githubusercontent.com/u/77738923?s=100&amp;u=92e54f60ca179f3e41c1a3610fb3ecdb9e233434&amp;v=4" /></a></td>
<td><a href="https://github.com/stephanie-owen"><img
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ navbar:
href: articles/using_mrip_data.html
- text: "Using {survdat} for Bottom Trawl Indicators"
href: articles/using_survdat_data.html
- text: "Comparison of condition data methods"
href: articles/compare_condition.html
- text: "Functions"
href: reference/index.html
- text: "News"
Expand Down
Binary file added data-raw/Survdat_2024.RData
Binary file not shown.
Binary file removed data-raw/catch_landings_great_hammerhead.Rds
Binary file not shown.
Binary file added data-raw/condition.rds
Binary file not shown.
Binary file not shown.
Loading
Loading