Skip to content
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: stockplotr
Title: Tables and Figures for Stock Assessments
Version: 0.7.0
Version: 0.9.0
Authors@R: c(
person("Samantha", "Schiano", , "samantha.schiano@noaa.gov", role = c("aut", "cre"),
comment = c(ORCID = "0009-0003-3744-6428")),
Expand Down Expand Up @@ -48,6 +48,7 @@ Imports:
prodlim,
quarto,
scales,
stats,
stringr,
tibble,
tidyr,
Expand Down
7 changes: 4 additions & 3 deletions R/convert_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @param file Assessment model output file path
#' @param model Assessment model used in evaluation ("ss3", "bam",
#' "asap", "fims", "amak", "ms-java", "wham", "mas").
#' "fims").
#' @param fleet_names Names of fleets in the assessment model as
#' shortened in the output file. If fleet names are not properly read, then
#' indicate the fleets names as an acronym in a vector
Expand Down Expand Up @@ -1745,8 +1745,9 @@ convert_output <- function(
#### JABBA ####
} else if (tolower(model) == "jabba") {
cli::cli_abort("JABBA output not currently compatible.")
#### FIMS ####
} else if (model == "fims") {
if (grepl(".RDS", file)) {
if (is.character(file) && length(file) == 1) {
fims_output <- readRDS(file)
} else {
fims_output <- file
Expand All @@ -1761,7 +1762,7 @@ convert_output <- function(
cli::cli_abort(c(
message = "Output file not compatible.",
"i" = "`model` entered as {model}.",
"i" = "Accepted `model` options: SS3, BAM, WHAM, AMAK, JABBA."
"i" = "Accepted `model` options: ss3, bam, or fims."
))
}

Expand Down
7 changes: 6 additions & 1 deletion R/plot_natural_mortality.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ plot_natural_mortality <- function(
facet = c(group, facet)
)

processed_data <- processing[[1]]
processed_data <- processing[[1]]
if (is.null(group)) {
processed_data <- processed_data |>
dplyr::mutate(group_var = "1") # set group var without anything since we are using group as age
}

if (!is.null(processing[[3]])) facet <- processing[[3]]
# make sure group is the one input by user
if (!is.null(group)) {
Expand Down
7 changes: 4 additions & 3 deletions R/plot_spawning_biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' also be made relative to this reference line rather than in absolute units.
#'
#' @param dat A data frame or names list of data frames (input as `list()`)
#' returned from \link[asar]{convert_output}. The first data frame in the list
#' returned from \link[stockplotr]{convert_output}. The first data frame in the list
#' is used in calculation of a reference line if one is present
#' @param geom A string stating the geom used for the plot. Default is "line".
#' Options include "line", "point", or "area"
Expand Down Expand Up @@ -117,7 +117,7 @@ plot_spawning_biomass <- function(
# Filter data for spawning biomass
prepared_data <- filter_data(
dat = dat,
label_name = "spawning_biomass$",
label_name = "^spawning_biomass$",
geom = geom,
era = era,
group = group,
Expand Down Expand Up @@ -166,7 +166,8 @@ plot_spawning_biomass <- function(
geom = geom,
ylab = spawning_biomass_label,
group = group,
facet = facet,
# add check in case facet is returned as character(0)
facet = if (length(facet) > 0) facet else NULL,
...
)
# Add reference line
Expand Down
32 changes: 19 additions & 13 deletions R/process_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,27 @@ process_data <- function(
# check if value varies in ANY year
# pivot data for 1st indexed data and check if all the same
if (length(index_variables) > 0) {
pivot_data <- data |>
dplyr::select(tidyselect::any_of(c("year", "age", "estimate", index_variables))) |>
tidyr::pivot_wider(
id_cols = c(year),
names_from = tidyselect::any_of(index_variables),
values_from = estimate
) |>
suppressWarnings()
column_data <- pivot_data[-1]
# if (index_variables == "age" | index_variables == "year") {
# # if age or year is the only other index variable, then get data so there is a single column as expected in column_data
# pivot_data <- data
# column_data <- pivot_data[["estimate"]]
# } else {
pivot_data <- data |>
dplyr::select(tidyselect::any_of(c("year", "age", "estimate", index_variables))) |>
tidyr::pivot_wider(
id_cols = c(year),
names_from = tidyselect::any_of(index_variables),
values_from = estimate
) |>
suppressWarnings()
column_data <- pivot_data[-1]
# }
} else {
# Look at group_var and identify if there is a needed grouping or can just plot one year
pivot_data <- data |>
dplyr::select(tidyselect::any_of(c("year", "age", "estimate", "group_var"))) |>
tidyr::pivot_wider(
id_cols = c(year),
id_cols = if ("year" %in% colnames(data)) "year" else NULL,
names_from = group_var,
values_from = estimate
) |>
Expand Down Expand Up @@ -352,7 +358,7 @@ process_table <- function(
mod_data <- dplyr::filter(dat, model == mod)
mod_index <- check_grouping(mod_data)
mod_names <- rep(mod, length(mod_index))
mod_index <- setNames(mod_index, mod_names)
mod_index <- stats::setNames(mod_index, mod_names)
index_variables <- c(index_variables, mod_index)
}

Expand Down Expand Up @@ -409,7 +415,7 @@ process_table <- function(
mod_data <- dplyr::filter(dat, model == mod)
mod_index <- check_grouping(mod_data)
mod_names <- rep(mod, length(mod_index))
mod_index <- setNames(mod_index, mod_names)
mod_index <- stats::setNames(mod_index, mod_names)
index_variables <- c(index_variables, mod_index)
}

Expand Down Expand Up @@ -495,7 +501,7 @@ process_table <- function(
table_list[[mod]] <- table_data

# This feels like backward progress
id_group_list[[mod]] <- lapply(setNames(mod_id_group, mod_id_group), function(x) {
id_group_list[[mod]] <- lapply(stats::setNames(mod_id_group, mod_id_group), function(x) {
unique(mod_dat[[x]])
})
} # close loop
Expand Down
5 changes: 4 additions & 1 deletion R/stockplotr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ globvar <- c(
"type", "uncertainty", "uncertainty_label", "val", "where", "year",
":=", "Year", "avg", "estimate_orig", "interm", "season", "tables_dir", "time", "total_fish",
"years_per_year", ".data", "cohort", "era", "expected_recruitment", "group_var", "model",
"plot_data", "quantile", "rda_dir", "reorder", "total_estimate", "zvar", "filter_data"
"plot_data", "quantile", "rda_dir", "reorder", "total_estimate", "zvar", "filter_data",
"Component", "age_bins", "alt_label", "final_df", "init", "keyword", "len_bins",
"like", "match_key", "morph", "nsim", "output", "output_order", "parm_stdev", "seas",
"sexes", "subseas", "unique_count", "value", "yr"
)
if (getRversion() >= "2.15.1") utils::globalVariables(globvar)
2 changes: 1 addition & 1 deletion R/utils_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ plot_timeseries <- function(
}

# Check if facet(s) are desired
if (!is.null(facet)) {
if (!is.null(facet) & length(facet) > 0) {
facet <- paste("~", paste(facet, collapse = " + "))
facet_formula <- stats::reformulate(facet)

Expand Down
2 changes: 1 addition & 1 deletion R/utils_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ merge_error <- function(table_data, uncert_lab, fleets, label, unit_label) {

# Rename final df with cleaned names
tab_dat <- tab_dat |>
dplyr::rename(any_of(rename_map_final)) |>
dplyr::rename(dplyr::any_of(rename_map_final)) |>
dplyr::rename_with(~ gsub("_", " - ", .)) # |>
# not sure if we want to keep this or not
# dplyr::select(where(~!all(is.na(.)) | !all(. == "-"))) # remove columns that are all NA or all "-"))
Expand Down
4 changes: 2 additions & 2 deletions data-raw/DATASET.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Path to SS3 output file
EX_REPORT_PATH <- file.path("inst", "extdata", "Report.sso")
# Install asar
devtools::install_github("nmfs-ost/asar")
devtools::install_github("nmfs-ost/stockplotr")
# Convert output
example_data <- asar::convert_output(EX_REPORT_PATH)
example_data <- stockplotr::convert_output(EX_REPORT_PATH)
# Save object as rda into raw_data
usethis::use_data(example_data, overwrite = TRUE)
2 changes: 1 addition & 1 deletion man/convert_output.Rd

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

2 changes: 1 addition & 1 deletion man/plot_biomass.Rd

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

2 changes: 1 addition & 1 deletion man/plot_fishing_mortality.Rd

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

2 changes: 1 addition & 1 deletion man/plot_indices.Rd

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

2 changes: 1 addition & 1 deletion man/plot_landings.Rd

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

2 changes: 1 addition & 1 deletion man/plot_natural_mortality.Rd

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

2 changes: 1 addition & 1 deletion man/plot_recruitment.Rd

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

2 changes: 1 addition & 1 deletion man/plot_recruitment_deviations.Rd

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

2 changes: 1 addition & 1 deletion man/plot_spawning_biomass.Rd

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

2 changes: 1 addition & 1 deletion man/plot_stock_recruitment.Rd

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

2 changes: 1 addition & 1 deletion man/save_all_plots.Rd

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

2 changes: 1 addition & 1 deletion man/table_landings.Rd

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

2 changes: 1 addition & 1 deletion man/write_captions.Rd

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

Loading