Skip to content

[feat] Create function that formats, checks, exports data to SIS - #623

Open
sbreitbart-NOAA wants to merge 31 commits into
mainfrom
sis-data
Open

sbreitbart-NOAA wants to merge 31 commits into
mainfrom
sis-data

Conversation

@sbreitbart-NOAA

Copy link
Copy Markdown
Collaborator

What is the feature?

  • Create function that formats, checks, exports data to SIS

How have you implemented the solution?

  • Creating export_to_sis(); ensuring SIS-related templates from stockplotr are saved in "report" folder; updating tests

Does the PR impact any other area of the project, maybe another repo?

  • Related to stockplotr::extract_sis_data()

sbreitbart-NOAA and others added 26 commits November 19, 2026 13:39
…ts if objects don't exist; fix json filename formula
…eparing json file in export_to_sis(); update documentation
… folder; update export_to_sis() to allow for 2 Primary categories
…ime series will not accept N/A or non-numerical values; ensure categories all have units and flags (feedback from Jeff)
…tract_sis_data(); update tests and documentation; correct when/where templates are created in create_template()

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical defects can corrupt SIS export data, upload assessments despite a negative response, and overwrite completed SIS CSVs during report updates.

12 open issues
2 files not reviewed
  • man/create_blank_sis.Rd: Generated file
  • man/export_to_sis.Rd: Generated file
What changed in this PR

Adds a SIS export workflow to asar’s stock-assessment reporting tools, using CSV templates compatible with stockplotr.

Changes:

  • Adds assessment validation, JSON formatting, and Google Drive submission through export_to_sis().
  • Integrates blank SIS templates into report creation and updates.
  • Adds documentation and tests, and refreshes table-rendering snapshots.
File Description
tests/​testthat/​test-export_to_sis.R Tests validation, JSON output, filenames, and mocked uploads.
tests/​testthat/​test-create_template.R Expects SIS templates in generated reports.
tests/​testthat/​_snaps/​create_tables_doc.md Updates expected table layout and pagination.
R/​update_report.R Adds SIS template creation during report updates.
R/​export_to_sis.R Implements CSV validation, JSON generation, and upload.
R/​create_template.R Adds SIS templates to new report directories.
R/​create_blank_sis.R Downloads blank SIS templates from stockplotr.
NAMESPACE Exports the two new SIS functions.
man/​export_to_sis.Rd Documents the export workflow and inputs.
man/​create_blank_sis.Rd Documents blank-template creation.
inst/​WORDLIST Adds assmt to the spelling dictionary.
DESCRIPTION Adds the googledrive runtime dependency.

Review effort: Balanced

Comment thread DESCRIPTION Resolved
Comment thread R/create_blank_sis.R Resolved
Comment thread R/export_to_sis.R Resolved
Comment thread R/export_to_sis.R Resolved
Comment thread R/export_to_sis.R Resolved
Comment thread R/create_blank_sis.R Resolved
Comment thread R/create_blank_sis.R Resolved
Comment thread R/export_to_sis.R Resolved
Comment thread R/export_to_sis.R Resolved
Comment thread R/export_to_sis.R Resolved
sbreitbart-NOAA and others added 3 commits November 19, 2026 16:19
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Updated the mutate function to ensure Value is treated as a character and added values_fill to pivot_wider.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Remove stale/superseded TODOs

* Address two active TODOs

* Update test snapshot
Comment thread R/create_blank_sis.R
#' hold data that will be transmitted to SIS.
#'
#' Default: the working directory (getwd())
#'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a details or returns section that says something like "sis_assmy_template.csv and sis_ts_template.csv". Also is there a place where we can document what each file could/should contain?

Comment thread R/create_blank_sis.R Resolved
Comment thread R/create_blank_sis.R
fs::path(dir, "sis_assmt_template.csv"))
}
if (!file.exists(fs::path(dir, "sis_ts_template.csv"))) {
download.file("https://raw.githubusercontent.com/nmfs-ost/stockplotr/refs/heads/main/inst/resources/sis_ts_template.csv",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment thread R/create_template.R

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there anyway to remove these formatting changes? I could see them causing merge conflicts. I am also confused how these applied considering this file isn't a part of the PR changes

Comment thread R/export_to_sis.R
#' [Automating data extraction for SIS](https://nmfs-ost.github.io/stockplotr/articles/extract-sis-data.html)
#' vignette for details).
#'
#' After you populate the templates according to the requirements in their metadata,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add somewhere that requires a valid NOAA login/credentials

Comment thread R/export_to_sis.R
sis_data_dir = getwd()
){
# Read in, clean, check, format assessment data
sis_assmt_data <- read.csv(file.path(sis_data_dir, "sis_assmt_template.csv"), stringsAsFactors = FALSE) |>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add condition to check if the file file is already in the sis_data_dir path in case people get confused

Comment thread R/export_to_sis.R
#' make_rda = T
#' )
#'
#' stockplotr::table_total_catch(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this example is confusing because there is no step which the sis files get made right?

Comment thread R/export_to_sis.R Resolved
Comment thread R/export_to_sis.R
} else if (any(primary_type %notin% valid_primary_cats)) {
invalid <- unique(primary_type[primary_type %notin% valid_primary_cats])
cli::cli_abort(
"Invalid Primary category detected ({.val {invalid}}). Only 'Fmort', 'Recruitment', 'Catch', and either 'Spawners' or 'Biomass' can be marked as 'Y' ('Index' must always be 'N')."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove the word primary. No one is going to understand that language, but we can keep it in a comment for our reference

Comment thread R/export_to_sis.R
} else if (any(table(primary_type) > 1)) {
dups <- names(which(table(primary_type) > 1))
cli::cli_abort(
"Multiple time series are marked as 'Y' within the same category ({.val {dups}}). Only one time series per category can be designated as Primary."

@Schiano-NOAA Schiano-NOAA Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Multiple time series are marked as 'Y' within the same category ({.val {dups}}). Only one time series per category can be designated as Primary."
"Multiple time series are marked as 'Y' within the same category ({.val {dups}}). Only one time series per category can be designated in this manner."

Same here. Thoughts?

Comment thread R/export_to_sis.R
)
} else if (sum(primary_type %in% sb_cats) > 1) {
cli::cli_abort(
"Both 'Spawners' and 'Biomass' are marked as 'Y' in the 'Primary' column. Only one time series combined across 'Spawners' and 'Biomass' can be designated as Primary."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@Schiano-NOAA Schiano-NOAA left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is getting there and almost ready! Unless assessment scientists are used to the language Jeff uses for SIS, then I think we should change the language in the messages. I feel like it is not our responsibility to teach users this language and is very confusing (however disregard everything I said if they should understand what we mean here).

I need to test this once more then I will approve

@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

Notes from testing:

  • we need to update the workshop to include the sis stuff (at the least screenshot of files and what gets made)
  • it's not clear in the messages which file you are talking about when you get an error. See example below
  • I am not sure how to proceed with testing the upload to gdrive, but since I initially coded it, I will assume it works. I wonder if there is a way for us to write an automated check for that
  • Could you include a reprex for me to test? I think this process is quite complex and will probably warrant a video to show the steps like the workshop
image

Comment thread R/export_to_sis.R
#' Default: The working directory.
#'
#' @details This function requires `sis_assmt_template.csv` and `sis_ts_template.csv` to be
#' present in `sis_data_dir`. You can generate these templates using either:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' present in `sis_data_dir`. You can generate these templates using either:
#' present and completed in `sis_data_dir`. You can generate these templates using either:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants