Repository navigation
[feat] Create function that formats, checks, exports data to SIS - #623
sbreitbart-NOAA wants to merge 31 commits into
Conversation
…ts if objects don't exist; fix json filename formula
…ad of listing dozens of arguments
…eparing json file in export_to_sis(); update documentation
…ants to send data to google drive
… 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()
There was a problem hiding this comment.
🟡 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
Declare jsonlite as a package dependency · New Preserve existing CSVs when updating templates · New Treat NA values as missing required fields · New Detect duplicate primary series before deduplicating categories · New Align unit ordering with category ordering · New Preserve series identity when pivoting multiple surveys · New Stop upload unless the response is affirmative · New Default the template directory to getwd() · New Avoid mandatory remote template downloads · New Fill pivot-created missing values with (blank) · New Reject missing or blank units · New Keep one description per category without deduplicating text · New
2 files not reviewed
man/create_blank_sis.Rd: Generated fileman/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
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
8178c2e to
9a9d723
Compare
| #' hold data that will be transmitted to SIS. | ||
| #' | ||
| #' Default: the working directory (getwd()) | ||
| #' |
There was a problem hiding this comment.
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?
| 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", |
There was a problem hiding this comment.
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
| #' [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, |
There was a problem hiding this comment.
I would also add somewhere that requires a valid NOAA login/credentials
| 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) |> |
There was a problem hiding this comment.
I would also add condition to check if the file file is already in the sis_data_dir path in case people get confused
| #' make_rda = T | ||
| #' ) | ||
| #' | ||
| #' stockplotr::table_total_catch( |
There was a problem hiding this comment.
I think this example is confusing because there is no step which the sis files get made right?
| } 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')." |
There was a problem hiding this comment.
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
| } 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." |
There was a problem hiding this comment.
| "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?
| ) | ||
| } 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." |
Schiano-NOAA
left a comment
There was a problem hiding this comment.
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
| #' 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: |
There was a problem hiding this comment.
| #' 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: |



What is the feature?
How have you implemented the solution?
Does the PR impact any other area of the project, maybe another repo?
stockplotr::extract_sis_data()