Skip to content

Commit

Permalink
correct maturity naming scheme for code 3s from port samples and a fe…
Browse files Browse the repository at this point in the history
…w other schemes; add an option for an updated naming scheme and one to revert to old assignments
  • Loading branch information
ecophilina committed Jan 10, 2025
1 parent 34e3839 commit 4741c1d
Show file tree
Hide file tree
Showing 3 changed files with 385 additions and 352 deletions.
47 changes: 40 additions & 7 deletions R/mat-freq-month.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ NULL
#' @param usability_codes An optional vector of usability codes.
#' All usability codes not in this vector will be omitted.
#' Set to `NULL` to include all samples.
#' @param name_convention Name convention defaults to "corrected"
#' will return the same names as "original", but with some corrections
#' in how they are applied to fish with maturity_code == 3. Use "original"
#' for the 2019-2023 version. Use "updated" for a new naming scheme that
#' uses "developing" and "developed" in place of "mature" and "ripe", but
#' note that rosettafish and other code may need to be updated to use these.
#' @param french Logical for French or English.
#' @export
#' @rdname plot_maturity_months
tidy_maturity_months <- function(dat, months = seq(1, 12),
usability_codes = c(0, 1, 2, 6), french = FALSE) {
usability_codes = c(0, 1, 2, 6), name_convention = "corrected", french = FALSE) {

if (!is.null(usability_codes)){
dat <- filter(dat, .data$usability_code %in% usability_codes)
Expand All @@ -40,18 +46,33 @@ tidy_maturity_months <- function(dat, months = seq(1, 12),

mat_df <- maturity_short_names # built-in package data

dat <- left_join(dat,
select(mat_df, sex, maturity_convention_code, maturity_code, maturity_name_short),
by = c("sex", "maturity_convention_code", "maturity_code")
)
if(name_convention == "original") {mat_df <- mat_df |> mutate(maturity_name_short = maturity_name_2019)}
if(name_convention == "corrected") {mat_df <- mat_df |> mutate(maturity_name_short = maturity_name_short)}

dat <- filter(dat, sex %in% c(1L, 2L))
dat <- dat %>% mutate(sex = ifelse(sex == 2L, "F", "M"))
mat_levels <- rev(c(
"Immature",
"Maturing",
"Mature",
"Gravid",
"Embryos",
"Ripe",
"Running Ripe",
"Uterine Eggs",
"Yolk Sac Pups",
"Term Pups",
"Spent",
"Resting"
))

if(name_convention == "updated") {
mat_df <- mat_df |> mutate(maturity_name_short = maturity_name_updated)

mat_levels <- rev(c(
"Immature",
"Maturing",
"Mature",
"Developing",
"Developed",
"Gravid",
"Embryos",
"Ripe",
Expand All @@ -60,9 +81,21 @@ tidy_maturity_months <- function(dat, months = seq(1, 12),
"Yolk Sac Pups",
"Term Pups",
"Spent",
"Resorbing",
"Resting"
))

}

dat <- left_join(dat,
select(mat_df, sex, maturity_convention_code, maturity_code, maturity_name_short),
by = c("sex", "maturity_convention_code", "maturity_code")
)

dat <- filter(dat, sex %in% c(1L, 2L))
dat <- dat %>% mutate(sex = ifelse(sex == 2L, "F", "M"))


mat_levels <- mat_levels[mat_levels %in% unique(dat$maturity_name_short)]
dat <- dat[!is.na(dat$maturity_name_short), , drop = FALSE]

Expand Down
Binary file modified data/maturity_short_names.rda
Binary file not shown.
Loading

0 comments on commit 4741c1d

Please sign in to comment.