| Title: | Streamline working with Terminal Area Management Modules |
|---|---|
| Description: | A convenient tool for interfacing with Terminal Area Manamagement Modules (TAMMs) in R environments. |
| Authors: | Collin Edwards [aut, cre] (ORCID: <https://orcid.org/0000-0002-4937-5159>), Ty Garber [aut] |
| Maintainer: | Collin Edwards <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.1.0 |
| Built: | 2026-07-09 16:48:32 UTC |
| Source: | https://github.com/cbedwards-dfw/TAMMsupport |
Helper function to parse full excel address into sheet, row, column. Removes
' from sheet names. If given a cell range, returns only the address of the first cell.
address_parser(address)address_parser(address)
address |
Character string of excel address, including sheet. |
list, with $sheet giving sheet name, $rows givng the row number, $cols giving the column number.
address_parser("SPS!AS3") address_parser("'Input Page'!$B$30")address_parser("SPS!AS3") address_parser("'Input Page'!$B$30")
Function to translate columns that "should" be numeric into numeric but doesn't do so if that would mean converting a true character string to NA.
as_numeric_safe(x)as_numeric_safe(x)
x |
Character vector |
Either numeric vector of x or (if that is lossy) character returns input.
Format chunks of dataframe to present as %s, round digits
chunk_formater_percenter(df, block_ranges, percent_digits = 1)chunk_formater_percenter(df, block_ranges, percent_digits = 1)
df |
dataframe of sheet to apply formatting to. |
block_ranges |
vector of characters specifying blocks of cells (in excel nomenclature) to format as %s |
percent_digits |
Decimal place to round to in percent |
Formatted version of df
Format chunks of dataframe to round digits
chunk_formater_rounder(df, block_ranges, digits = 1)chunk_formater_rounder(df, block_ranges, digits = 1)
df |
dataframe of sheet to apply formatting to. |
block_ranges |
vector of characters specifying blocks of cells (in excel nomenclature) to format as %s |
digits |
Decimal place to round to. |
Formatted version of df
Read in chunks of the 2A_Cmrkd sheet
chunk_read_2A_Cmrkd(full_sheet, start_col, end_col, table_name)chunk_read_2A_Cmrkd(full_sheet, start_col, end_col, table_name)
full_sheet |
entire raw spreadsheet |
start_col |
Letter of the column the chunk starts on |
end_col |
Letter of the column the chunk ends on |
table_name |
name of table |
Read chunk for table 2A_CUandM
chunk_read_2A_CUandM(full_sheet, start_col, end_col, table_name)chunk_read_2A_CUandM(full_sheet, start_col, end_col, table_name)
full_sheet |
entire raw spreadsheet |
start_col |
Letter of the column the chunk starts on |
end_col |
Letter of the column the chunk ends on |
table_name |
name of table |
Read in individual chunks for sheet 2A_Cu&M_N
chunk_read_2A_CUandM_N(full_sheet, start_col, end_col, table_name)chunk_read_2A_CUandM_N(full_sheet, start_col, end_col, table_name)
full_sheet |
entire raw spreadsheet |
start_col |
Letter of the column the chunk starts on |
end_col |
Letter of the column the chunk ends on |
table_name |
name of table |
Reads chunk of 2A_CUnmrkd sheet
chunk_read_2A_CUnmrkd(full_sheet, start_col, end_col, table_name)chunk_read_2A_CUnmrkd(full_sheet, start_col, end_col, table_name)
full_sheet |
entire raw spreadsheet |
start_col |
Letter of the column the chunk starts on |
end_col |
Letter of the column the chunk ends on |
table_name |
name of table |
Handles some of the repetitive tasks of processing individual chunks; this part is generalized and does not need to be different for each sheet. Lots of fiddliness in here because TAMM formatting is terrible
chunk_read_finisher( sheet_name, table_name, raw, raw_titles, data_er, do_er = TRUE )chunk_read_finisher( sheet_name, table_name, raw, raw_titles, data_er, do_er = TRUE )
sheet_name |
Name of sheet |
table_name |
Name of table |
raw |
. |
raw_titles |
. |
data_er |
. |
do_er |
Should ER be done? If FALSE, skips ER (useful for processing sections with no ER.) |
A list with $aeq and $er, each a dataframe
Effectively a wrapper function for read_limiting_stock with some formatting added in. Filters to unmarked naturals, just present ER values.
clean_limiting_stock(file)clean_limiting_stock(file)
file |
Name (and path) for TAMM files |
dataframe
Summarizes the differences in input sheets and returns as a table. Wrapper for xldiff::excel_diff_table()
compare_chinook_inputs( file_1, file_2, proportional_threshold = 0.001, absolute_threshold = NULL, digits_show = 6, trim_cols = TRUE, diff_only = TRUE )compare_chinook_inputs( file_1, file_2, proportional_threshold = 0.001, absolute_threshold = NULL, digits_show = 6, trim_cols = TRUE, diff_only = TRUE )
file_1 |
Filename of first TAMM file |
file_2 |
Filename of second TAMM file |
proportional_threshold |
Sets a threshold of proportional change below which differences should be ignored. For example, a value of 0.1 means any changes less than 10% will not be flagged as having changed. |
absolute_threshold |
Optional. Sets a threshold of absolute change below which differences should be ignored. For example, a value of 0.1 means any changes less than 0.1 will not be flagged as having changed. If provided, will override |
digits_show |
When there is a change in number values, how many digits should be shown in |
trim_cols |
Should columns that contain no differences be cut from the results? Defaults to TRUE. |
diff_only |
Should entries that do not contain differences be replaced by "" to help spot differences? Defaults to TRUE. |
Tibble of differences in the input files; only rows with differences are included. row_name variable gives the row name in the TAMM file, and column names match excel column names.
Adapted from framrsquared::filter_wa(), but (a) only for Chinook (at present), and (b) uses TAMM fishery ids, so includes
ids 72 and 73. Includes code for COHO based on FRAM ids. filter_tamm_wa() uses attributes to specify chinook or coho. To
directly filter for chinook or coho, use filter_tamm_wa_chin() or filter_tamm_wa_coho().
filter_tamm_wa(.data) filter_tamm_wa_chin(.data) filter_tamm_wa_coho(.data)filter_tamm_wa(.data) filter_tamm_wa_chin(.data) filter_tamm_wa_coho(.data)
.data |
Dataframe generated within this package |
a fishery_id column name.
## Not run: fram_dataframe |> filter_wa() ## End(Not run)## Not run: fram_dataframe |> filter_wa() ## End(Not run)
Designed for tracking the status of TAMM inputs, which are typically color coded.
Searches through specified sheet or sheets, looking for cells whose colors match the
target_cell argument. Returns a condensed list of those entries.
find_color_matches(file, target_cell, sheets = "Input Page")find_color_matches(file, target_cell, sheets = "Input Page")
file |
Character string of excel file name, including path if relevant |
target_cell |
Character string of excel address of cell with the cell shading of interest (e.g., "B4") |
sheets |
character string or character vector of sheets to search through |
tibble summarizing entries with the color of interest, including sheet, row and column ids, and row name (entry of first column in sheet)
## Not run: file = "chin tamms/Chin2023_Final.xlsx" find_color_matches(file, "B20") ## End(Not run)## Not run: file = "chin tamms/Chin2023_Final.xlsx" find_color_matches(file, "B20") ## End(Not run)
With argument sep = TRUE, will return data frame with separate
columns for the area and the the "class" (Net, Troll, Sport)
fishery_renamer(x, sep = FALSE)fishery_renamer(x, sep = FALSE)
x |
character vector of fishery names from TAMM or FRAM |
sep |
Should we return a dataframe with separate column for class of fishing? Defaults to FALSE |
#vector with cleaned fishery names OR dataframe with cleaned name ($full),
area without fishery type ($area) and type of fishery ($class).
Function is no longer needed for tamm_diff now that openxlsx
format_key_tamm_sheets_chin( dat, percent_digits = 1, numeric.digits = 1, numeric.digits.small = 4 )format_key_tamm_sheets_chin( dat, percent_digits = 1, numeric.digits = 1, numeric.digits.small = 4 )
dat |
list of dataframes corresponding to the overview, limiting stock, and inputs tabs. Must be named |
percent_digits |
Optional, number of decimal places to round percentages to before comparison. Defaults to 1. |
numeric.digits |
Optional, number of decimal places to round non-percentage numerics to before comparison. Applied to numbers that are expected to have natural units of whole numbers (e.g. numbers of fish). Defaults to 1. |
numeric.digits.small |
Optional, number of decimal places to round non-percentage numerics to before comparison. Applied to numbers that are expected to be small (e.g. rates, proportions) Defaults to 4. |
list of dataframes with same structure as dat, contents modified.
Modify list of Coho TAMM spreadsheet dataframes to facilitate comparison.
format_key_tamm_sheets_coho( dat, percent_digits = 2, numeric.digits = 1, numeric.digits.small = 4 )format_key_tamm_sheets_coho( dat, percent_digits = 2, numeric.digits = 1, numeric.digits.small = 4 )
dat |
list of dataframes corresponding to the overview, limiting stock, and inputs tabs. Must be named |
percent_digits |
Optional, number of decimal places to round percentages to before comparison. Defaults to 1. |
numeric.digits |
Optional, number of decimal places to round non-percentage numerics to before comparison. Applied to numbers that are expected to have natural units of whole numbers (e.g. numbers of fish). Defaults to 1. |
numeric.digits.small |
Optional, number of decimal places to round non-percentage numerics to before comparison. Applied to numbers that are expected to be small (e.g. rates, proportions) Defaults to 4. |
list of dataframes with same structure as dat, contents modified.
Format TAMM overview for easy printing
format_overview(dat_overview)format_overview(dat_overview)
dat_overview |
dataframe of TAMM overview page, as produced by read_overview() |
list with the formatted data, a vector of indent information, and a vector of bolding information.
Helper function to add spaces to excel formulas to improve readability. Can also add newlines based on a character or regular expression
formula_formater(x, newline_breakpoint = NULL)formula_formater(x, newline_breakpoint = NULL)
x |
Character string containing an excel formula |
newline_breakpoint |
Pattern to identify locations for newlines. Could be a single character (e.g. |
character string
formula_formater("(SUM(A1:A4)*5/11)/(B3-B4)") formula_formater("(SUM(A1:A4)*5/11)/(B3-B4)", newline_breakpoint = "/") formula_formater("(SUM(A1:A4)*5/11)/(B3-B4)", newline_breakpoint = "[*-+/]")formula_formater("(SUM(A1:A4)*5/11)/(B3-B4)") formula_formater("(SUM(A1:A4)*5/11)/(B3-B4)", newline_breakpoint = "/") formula_formater("(SUM(A1:A4)*5/11)/(B3-B4)", newline_breakpoint = "[*-+/]")
Intended for internal use within formatting functions. Note that percents in excel are read in as proportions in R – this makes them percents to make saved files more readable.
fun_percenter(x, percent_digits)fun_percenter(x, percent_digits)
x |
Character vector, presumably containing some entries that are numbers in character form |
percent_digits |
Number of digits to round to after converting to percents |
character vector with individual entries converted to percentages and rounded as appropriate.
Intended for internal use within formatting functions.
fun_rounder(x, digits)fun_rounder(x, digits)
x |
Character vector, presumably containing some entries that are numbers in character form |
digits |
Number of digits to round numeric items to |
Uses output of format_overview()
kable_overview(dat_overview, ind_indent, col_bold)kable_overview(dat_overview, ind_indent, col_bold)
dat_overview |
formatted data, first item of format_overview() output |
ind_indent |
Vector of indices that need indenting to match TAMM overview formatting. Second item of format_overview() output |
col_bold |
vector of names for bolding to match TAMM overview formatting. Third item of format_overview() output. |
html table
Helper function to find all references in list created within tracer_formula, and create a simple dataframe
representing all the "edges" of the traced network (that is, all the connections between cells).
Gets called in trace_formula() to generate the $references component of the output.
make_tracer_edges(address_list)make_tracer_edges(address_list)
address_list |
The |
tibble.
$from is the index of the cell that is referenced,
$to is hte index of the cell that is doing the referencing
$from_name and $to_name are the excel addresses of the same.
make_tracer_network(tracer_list, save_path = NULL, newline_breakpoint = NULL)make_tracer_network(tracer_list, save_path = NULL, newline_breakpoint = NULL)
tracer_list |
Output of a |
save_path |
Optional, defaults to NULL. Provide a file path + name to save an html of the visualization. Make sure file name ends in |
newline_breakpoint |
Optional character string used to add breakpoints to formulas to improve readability. Can be simple character or regular expression; See |
Render the dependency network created in trace_formula(); optionally save this to an interactive .html.
interactive visNetwork object
## Not run: trace_network = trace_formula(path = "NOF material/NOF 2024/NOF 2/Chin1624.xlsx", cell_start = "SPSmrkd!AS20") make_tracer_network(trace_network) ## End(Not run)## Not run: trace_network = trace_formula(path = "NOF material/NOF 2024/NOF 2/Chin1624.xlsx", cell_start = "SPSmrkd!AS20") make_tracer_network(trace_network) ## End(Not run)
Helper function to parse list created within trace_formula into a tibble with each cell represented by a row.
Called in trace_formula() to generate the $cells component of the output.
make_tracer_nodes(address_list)make_tracer_nodes(address_list)
address_list |
The |
tibble summarizing each cell in the tracing. See trace_formula() for details.
Read and combine aeq sections form tables 2a-2c
process_2ac_aeqs(tab_2a, tab_2b, tab_2c)process_2ac_aeqs(tab_2a, tab_2b, tab_2c)
tab_2a |
the "Table 2a" section of one of the 2ac sheets, read in with
a |
tab_2b |
same, but 2b |
tab_2c |
same, but 2c |
dataframe of AEQ values for each stock in longform
function to process + combine the er sections from tables 2a-2c, used below
process_2ac_ers(tab_2a, tab_2b, tab_2c)process_2ac_ers(tab_2a, tab_2b, tab_2c)
tab_2a |
the "Table 2a" section of one of the 2ac sheets, read in with
a |
tab_2b |
same, but 2b |
tab_2c |
same, but 2c |
dataframe of ers in longform
Quick helper function to format vectors that contain text and ERs
quick_er_format(x)quick_er_format(x)
x |
character vector |
Primarily intended as a helper function for trace_formula(), but could be useful for
other excel tasks. Drops $ and ' symbols from addresses to simplify parsing.
range_splitter(address)range_splitter(address)
address |
Character string of excel cell range, as in "B10:C15" or "'Input Sheet'!AS30:AS40" |
vector of individual excel-style cell addresses within that range
range_splitter("B10:C15") range_splitter("'Input Sheet'!$AS30:$AS40")range_splitter("B10:C15") range_splitter("'Input Sheet'!$AS30:$AS40")
Gathers and cleans the AEQ and ER information for tamm sheets 2aCmrkd,
2aCUnmkrd, 2aCUandM, and 2aCUandM_N.
read_2a_sheets(tamm_filepath, stock_cleanup = TRUE)read_2a_sheets(tamm_filepath, stock_cleanup = TRUE)
tamm_filepath |
TAMM filepath |
stock_cleanup |
Clean up stock name capitalization? Logical, defaults to TRUE. |
list, with $aeq containing the primary information (AEQs of fishery impacts on each stock) and $er containing the ER information at the bottom of the spreadsheets.
## Not run: library(here) filepath <- here("tamms/Chin2025.xlsx") res <- read_2a_sheets(filepath) jdf <- read_jdf(filepath) ## End(Not run)## Not run: library(here) filepath <- here("tamms/Chin2025.xlsx") res <- read_2a_sheets(filepath) jdf <- read_jdf(filepath) ## End(Not run)
Reads sheet of 2A_Cmrkd
read_2aCmrkd(tamm_filepath, stock_cleanup = TRUE)read_2aCmrkd(tamm_filepath, stock_cleanup = TRUE)
tamm_filepath |
path to file |
stock_cleanup |
Do cleanup of capitalization? |
a list, with $aeq (the main parts of each table) and $er (the very bottom section)
Read and process all parts of sheet 2A CU and M
read_2aCUandM(tamm_filepath, stock_cleanup = TRUE)read_2aCUandM(tamm_filepath, stock_cleanup = TRUE)
tamm_filepath |
Tamm filepath |
stock_cleanup |
Clean up weird capitalization? Logical, defaults to TRUE |
a list, with $aeq (the main parts of the table) and $er (the very bottom section) @return
Read and combine all chunks for sheet 2A CU and M_N
read_2aCUandM_N(tamm_filepath, stock_cleanup = TRUE)read_2aCUandM_N(tamm_filepath, stock_cleanup = TRUE)
tamm_filepath |
Tamm filepath |
stock_cleanup |
Clean up stock name capitalization? Logical, defaults to TRUE |
read all info for 2aCUnmrkd and process it.
read_2aCUnmrkd(tamm_filepath, stock_cleanup = TRUE)read_2aCUnmrkd(tamm_filepath, stock_cleanup = TRUE)
tamm_filepath |
Tamm filepath |
stock_cleanup |
Logical, defaults to TRUE. Convert weird capitalization to lowercase? |
a list, with $aeq (the main parts of the table) and $er (the very bottom section)
Read in AEQ and ER information from the JDF sheet
read_jdf(tamm_filepath, stock_cleanup = TRUE)read_jdf(tamm_filepath, stock_cleanup = TRUE)
tamm_filepath |
TAMM filepath |
stock_cleanup |
Clean up stock name capitalization? Logical, defaults to TRUE. |
List, with $aeq containing the combined AEQ information that is spread across multiple chunks in the TAMM sheet. List also contains $er = NULL, to provide parallel outputs to read_2a_sheets, which does have a non-null $er item in the output list.
## Not run: library(here) filepath <- here("tamms/Chin2025.xlsx") jdf <- read_jdf(filepath) ## End(Not run)## Not run: library(here) filepath <- here("tamms/Chin2025.xlsx") jdf <- read_jdf(filepath) ## End(Not run)
Read in AEQ and ER information from the JDF Unmarked sheet
read_jdf_unmarked(tamm_filepath, stock_cleanup = TRUE)read_jdf_unmarked(tamm_filepath, stock_cleanup = TRUE)
tamm_filepath |
TAMM filepath |
stock_cleanup |
Clean up stock name capitalization? Logical, defaults to TRUE. |
List, with $aeq containing the combined AEQ information that is spread across multiple chunks in the TAMM sheet. List also contains $er = NULL, to provide parallel outputs to read_2a_sheets, which does have a non-null $er item in the output list.
## Not run: library(here) filepath <- here("tamms/Chin2025.xlsx") jdf <- read_jdf_unmarked(filepath) ## End(Not run)## Not run: library(here) filepath <- here("tamms/Chin2025.xlsx") jdf <- read_jdf_unmarked(filepath) ## End(Not run)
Read Chinook TAMM files to extract the key sheets
read_key_tamm_sheets_chin(file)read_key_tamm_sheets_chin(file)
file |
#Tamm file name |
List of dataframes: $overview, $limiting, and $input
Read Chinook TAMM files to extract the key sheets
read_key_tamm_sheets_coho(file)read_key_tamm_sheets_coho(file)
file |
#Tamm file name |
List of dataframes: $two, $tami, and $wacoast
Reads in the table, adds fishery type information.
read_limiting_stock(file, longform = FALSE)read_limiting_stock(file, longform = FALSE)
file |
Tamm name (and path) |
longform |
Should results be in long form (good for R stuff) ( |
data frame summarizing the TAMM limiting stock tab. The "block" of the limiting tab is identified with column "stock_type". "first_section" is the first section in the TAMM; this section is primarily natural fish but includes some hatchery fish if they were included in management objectives. "ALL_H" is all hatchery fish (in TAMM, block starts on row 81), "UM_H" is unmarked hatchery (in TAMM, starts on row 160), "UM_N" is unmarked naturals (in TAMM, starts row 239), "AD_H" is marked hatchery (in TAMM, starts row 318), and "AD_N" is marked naturals (unless programs begin marking natural fish, this should always be all 0s; in TAMM starts row 397).
Extract and format management criterion from Chinook TAMM
read_management_chin(file)read_management_chin(file)
file |
filename, including filepath if appropriate |
Tibble, with $management_name giving the name of the management criteria as specified in
the TAMM, $management_criteria giving a list of dataframes with the associated management criteria, formatted appropriately, and
$notes giving a list of character vectors with notes (if any) to help interpret the criteria.
## Not run: cur.management = read_management_chin("Code Inputs/Pre-Season/TAMMs/2013_Final W_BP7.1.xlsx") ## End(Not run)## Not run: cur.management = read_management_chin("Code Inputs/Pre-Season/TAMMs/2013_Final W_BP7.1.xlsx") ## End(Not run)
Read overview sheet from TAMM and return key stock
read_overview(path)read_overview(path)
path |
filename (including path) to Chinook TAMM |
dataframe
The stock column of the overview tab uses R-unfriendly approaches to store
season, overall stock name, and individual stocks in the stock column of the TAMM. read_overview_complete
splits these into separate columns: season, primary_stock, and stock.
For three stock (Green, Puyallup, Skokomish), the tamm presents model predictions across two rows with
a single stock name due to merged cells. The stock column in the output preserves this information;
the entry corresponding to the second row has the suffix "_row2".
read_overview_complete(path)read_overview_complete(path)
path |
filename (including path) to Chinook TAMM |
Dataframe containing all infomration from cells A2:H34 of the "ER_ESC_Overview_New" sheet.
Extract Treaty and Nontreaty numbers from "2A_CU&M_H+N" TAMM sheet. For Elwha and Dungeoness, separate allocations are calculated using column O of the JDF tab
read_tnt_allocation_chin(file)read_tnt_allocation_chin(file)
file |
Character vector. Filename (including path) for chinook TAMM |
Currently provides dataframe with stock.original column identifying the stock based on their names
in the TAMM, and stock.clean with more human-readable names (which are generally consistent
with other stock names, like those used to label the management criterion).
dataframe with the treaty and nontreaty mortalities at each stock.
Internal tool to simplify converting TAMM sheet to stock management criterion lists. See
read_management_chin() for example use.
reformat_management( df, cols.percent, rows.percent = NULL, rows.header = 2, notes = NULL )reformat_management( df, cols.percent, rows.percent = NULL, rows.header = 2, notes = NULL )
df |
dataframe trimmed from TAMM management page to just the relevant stock's criterion. |
cols.percent |
Column numbers for columns that should be converted to percents. |
rows.percent |
Character vector of row sub-stock names identifying rows (if any) that should be translated to percents. Defaults to NULL. Developed to accomodate "CERC (SUS)" in Snohomish. |
rows.header |
How many rows are used to make up the header? Defaults to 2, but sometimes header block in TAMM is 1 row. |
notes |
Optional. Character vector, each item of which is a separate note associated with this stock. Generally based on comments in excel doc, can also feed in "extra" rows from TAMM that contain caveats. |
Stock management criterion list, containing dataframe extracted from TAMM and notes hard-coded in based on TAMM cell comments.
Helper function to check an atomic string and convert to numeric if it contains a legal number.
safe_convert_numeric(x)safe_convert_numeric(x)
x |
character string |
Input formatted as character string or numeric
safe_convert_numeric("AS20-BC2") safe_convert_numeric("10.5")safe_convert_numeric("AS20-BC2") safe_convert_numeric("10.5")
Intended use case is to compare low, mid, and high ocean option.
tamm_compare( tamm_names, tamm_path = getwd(), fisheries = NULL, clean = TRUE, overwrite = TRUE )tamm_compare( tamm_names, tamm_path = getwd(), fisheries = NULL, clean = TRUE, overwrite = TRUE )
tamm_names |
character vector of the three tamm files to compare (including .xlsx suffix). |
tamm_path |
Absolute path to directory containing the tamm file. |
fisheries |
Optional, numeric vector of fishery IDs to filter to before plotting fishery-specific ER for each stock. Defaults to NULL (no filtering). |
clean |
Should the intermediate .qmd files used to make the report be deleted afterwards? Logical, defaults to |
overwrite |
Should the intermediate .qmd files or the final report be overwritten if those files already exist?; Logical, defaults to |
Nothing
## Not run: tamm_path <- "C:/Users/edwc1477/Documents/WDFW FRAM team work/NOF material/NOF 2024/FRAM" tamm_names <- c("Chin1024.xlsx", "Chin1124.xlsx", "Chin1224.xlsx") tamm_compare3(tamm_names = tamm_names, tamm_path = tamm_path) ## End(Not run)## Not run: tamm_path <- "C:/Users/edwc1477/Documents/WDFW FRAM team work/NOF material/NOF 2024/FRAM" tamm_names <- c("Chin1024.xlsx", "Chin1124.xlsx", "Chin1224.xlsx") tamm_compare3(tamm_names = tamm_names, tamm_path = tamm_path) ## End(Not run)
Intended use case is to compare low, mid, and high ocean option.
tamm_compare3(tamm_names, tamm_path = getwd(), clean = TRUE, overwrite = TRUE)tamm_compare3(tamm_names, tamm_path = getwd(), clean = TRUE, overwrite = TRUE)
tamm_names |
character vector of the three tamm files to compare (including .xlsx suffix). |
tamm_path |
Absolute path to directory containing the tamm file. |
clean |
Should the intermediate .qmd files used to make the report be deleted afterwards? Logical, defaults to |
overwrite |
Should the intermediate .qmd files or the final report be overwritten if those files already exist?; Logical, defaults to |
Nothing
## Not run: tamm_path <- "C:/Users/edwc1477/Documents/WDFW FRAM team work/NOF material/NOF 2024/FRAM" tamm_names <- c("Chin1024.xlsx", "Chin1124.xlsx", "Chin1224.xlsx") tamm_compare3(tamm_names = tamm_names, tamm_path = tamm_path) ## End(Not run)## Not run: tamm_path <- "C:/Users/edwc1477/Documents/WDFW FRAM team work/NOF material/NOF 2024/FRAM" tamm_names <- c("Chin1024.xlsx", "Chin1124.xlsx", "Chin1224.xlsx") tamm_compare3(tamm_names = tamm_names, tamm_path = tamm_path) ## End(Not run)
Compare key sheets of TAMM files
tamm_diff( file_1, file_2, results_name, proportional_threshold = 0.001, absolute_threshold = NULL, extra_width = NULL )tamm_diff( file_1, file_2, results_name, proportional_threshold = 0.001, absolute_threshold = NULL, extra_width = NULL )
file_1 |
name of first TAMM file to compare. Include file path if file is not in working directory. |
file_2 |
name of second TAMM file to compare. Include file path if file is not in working directory. |
results_name |
name of output sheets. Include file path if save location is not in working directory. |
proportional_threshold |
Sets a threshold of proportional change below which differences should be ignored. For example, a value of 0.1 means any changes less than 10% will not be flagged as having changed. |
absolute_threshold |
Optional. Sets a threshold of absolute change below which differences should be ignored. For example, a value of 0.1 means any changes less than 0.1 will not be flagged as having changed. If provided, will override |
extra_width |
How much extra width should be added to columns that changed? Helpful to improve readability, since changed cells have longer entries. Numeric, defaults to 0.4. |
## Not run: tamm_diff( file_1 = here("FRAM/Chin1124.xlsx"), file_2 = here("NOF 2/Chin2524.xlsx"), results_name = here("Chin 1124 vs Chin 2524.xlsx") ) ## End(Not run)## Not run: tamm_diff( file_1 = here("FRAM/Chin1124.xlsx"), file_2 = here("NOF 2/Chin2524.xlsx"), results_name = here("Chin 1124 vs Chin 2524.xlsx") ) ## End(Not run)
Functions that add formatting to broadly replicate the formatting of the TAMM sheets. Colored foregrounds have been toned down to help change highlighting pop, and some of the complicated or superfluous formatting has been skipped.
tamm_format_overview(wb, diff.sheet, tabname = "overview") tamm_format_limiting(wb, tabname = "limiting") tamm_format_input(wb, tabname = "input", wrap.text = FALSE) tamm_format_wacoast(wb, tabname = "wacoast")tamm_format_overview(wb, diff.sheet, tabname = "overview") tamm_format_limiting(wb, tabname = "limiting") tamm_format_input(wb, tabname = "input", wrap.text = FALSE) tamm_format_wacoast(wb, tabname = "wacoast")
wb |
|
diff.sheet |
For |
tabname |
Name of sheet in the wb to be modified. Defaults to correct value. |
wrap.text |
Should specific cells with long content use text wrapping? Defaults to FALSE. |
Generate report of figures from TAMM file
tamm_report( tamm_name, tamm_path = getwd(), clean = TRUE, overwrite = TRUE, additional_children = NULL, additional_support_files = NULL )tamm_report( tamm_name, tamm_path = getwd(), clean = TRUE, overwrite = TRUE, additional_children = NULL, additional_support_files = NULL )
tamm_name |
Name of tamm file (including .xlsx suffix). Character atomic |
tamm_path |
Absolute path to directory containing the tamm file. |
clean |
Should the intermediate .qmd files used to make the report be deleted afterwards? Logical, defaults to |
overwrite |
Should the intermediate .qmd files or the final report be overwritten if those files already exist?; Logical, defaults to |
additional_children |
Optional argument with filepath(s) to additional quarto child documents (see |
additional_support_files |
Optional argument with filepath(s) to additional files needed by additional quarto documents. Files will be copied into the same directory as the TAMM for
easy reading/use by |
This function generates a summary report of a single chinook TAMM (Terminal Area Management Module) file. The common use case is to call this function for a tamm, and then view the resulting html report (which will be generated in the same folder as the TAMM). However, this function also provides substantial flexibility in the form of optional user-created child quarto documents, which requires some additional context to develop and use.
tamm_report is implemented using a parameterized quarto report and a child quarto document, which are included in the package.
The resulting report includes some broadly useful content – currently, a replication of the overview TAMM sheet and
bar charts showing the breakdown of exploitation rates by fishery for each stock listed in the
limiting stock complete TAMM sheet. However, individuals or organizations may consistently want
additional, specific visualizations based on their own needs. For example, individual tribes may want
to visualize impacts on a single stock, but use AEQ instead of ER rates. The tamm_report function is
designed to integrate these extra components with the additional_children argument.
The basic principle is that the individual or group can write a reusable "child" .qmd file, see this explanation using Rmarkdown), which will effectively
be inserted into the main report. As an example, we might create a simple additional
child .qmd file called extra-tamm-child.qmd to include a small table summarizing a few
key aspects of the Nooksack Earlies stock. The contents of that file are provided in the example below.
When we call tamm_report(), we can include as an argument additional_children = with the file name (including file path) for
our new file. In this way we can easily include this extra content any time we create a tamm report. If desired,
multiple child files can be created, and additional_children can take a character vector with each child file name.
When writing child documents, formatting and chunks work akin to copy-pasting a section of a quarto file out of the main file. (To easily
access the main quarto file, run tamm_report() with clean = FALSE, which will leave tamm-visualizer.qmd and tamm-visualizer-child.qmd files in the folder with the TAMM file).
The child document will have access to key objects
dat.all: the output of read_limiting_stock with longform = TRUE called on the TAMM;
dat_overview: the output of of read_overview called on the TAMM;
and dat: the specific filtered and formatted version of the limiting stock data generated in the limiting stock tab chunk of tamm-visualizer.qmd and used in generating the unmarked natural stock exploitation rate figures.
When developing a child document, it may be useful to create in the working environment versions of dat.all and dat_overview from an example TAMM to facilitate
writing appropriate filters, plot-making code, etc. The primary quarto report loads in the tidyverse, framrsquared, kableExtra, and TAMMsupport packages,
but you can include additional packages for the child documents as needed by adding library(packagename calls just
like in any other context.
If the additional_children files need to read contents of additional files (or call children .qmd files of their own
to streamline looping over stocks or fisheries), the file paths to these supplemental
files can be provided in the additional.support files argument. These files will be copied into the
same folder as the .qmd files, so the children quarto files can be written to access the supplemental
files without dealing with file paths.
For questions/support in developing child documents to extend the report, contact Collin Edwards at WDFW.
Nothing
## Not run: ##### CONTENTS FOR extra-tamm-child.qmd #####----------------------------- ## Test section Hypothetical world in which we want a table summarizing the impacts of three fisheries on the "Nooksack Earlies" stock. ```{r} kable(dat |> filter(stock == "Nooksack Earlies") |> filter(fishery_id %in% 16:18)) ``` #### END CONTENTS FOR extra-tamm-child.qmd #####-------------------------- tamm_path = "C:/Users/edwc1477/Documents/WDFW FRAM team work/NOF material/NOF 2024/NOF 2" tamm_name = "Chin2124.xslx" tamm_report(tamm_name = "Chin2124.xlsx", tamm_path = tamm_path) ## Now with our extra content, presuming `extra-tamm-child.qmd` is saved in our documents folder tamm_report(tamm_name = "Chin2124.xlsx", tamm_path = tamm_path, additional_children = "C:/Users/JohnDoe/Documents/extra-tamm-child.qmd") ## End(Not run)## Not run: ##### CONTENTS FOR extra-tamm-child.qmd #####----------------------------- ## Test section Hypothetical world in which we want a table summarizing the impacts of three fisheries on the "Nooksack Earlies" stock. ```{r} kable(dat |> filter(stock == "Nooksack Earlies") |> filter(fishery_id %in% 16:18)) ``` #### END CONTENTS FOR extra-tamm-child.qmd #####-------------------------- tamm_path = "C:/Users/edwc1477/Documents/WDFW FRAM team work/NOF material/NOF 2024/NOF 2" tamm_name = "Chin2124.xslx" tamm_report(tamm_name = "Chin2124.xlsx", tamm_path = tamm_path) ## Now with our extra content, presuming `extra-tamm-child.qmd` is saved in our documents folder tamm_report(tamm_name = "Chin2124.xlsx", tamm_path = tamm_path, additional_children = "C:/Users/JohnDoe/Documents/extra-tamm-child.qmd") ## End(Not run)
trace_formula( path, cell_start, max_it = 5000, verbose = TRUE, split_ranges = FALSE )trace_formula( path, cell_start, max_it = 5000, verbose = TRUE, split_ranges = FALSE )
path |
Filepath of an excel file |
cell_start |
Character string of intiial cell in excel format. MUST include sheet name (e.g. "SPS!AS20", not "AS20") |
max_it |
Maximum iterations; used as a failsafe to ensure function eventually in case of circular error. Defaults to 5000; increase if actual dependency network is likely to have more than 5000 nodes. |
verbose |
Print cell addresses to console during tracing? Logical, defaults to |
split_ranges |
When encountering a reference that includes a cell range, trace backwards for all cells (TRUE) or just the first cell in the range (FALSE)? Logical, defaults to |
"trace object" – list defining the dependency network.
$cellstibble summarizing each of the cells in the dependency network, starting with the cell_start. Within this,
$id is an index; $label is the cell address; $formula is the formula in that cell if there is a formula, otherwise it is the
contents of the cell, $contents is the non-formula cell contents (i.e., if a formula is present, $contents will be the results of the formula);
$is.formula is a logical identifying if this cell contains a formula, or is purely a numeric / string / etc contents;
$addresses.referenced is a character vector of all excel addresses in $formula, and sheet is the sheet associated with the current cell.
$referencesis a tibble summarizing each of the edges of the dependency network – that is, all of the references in one cell to another. $from is the index of the cell that is referenced; $to is the index of the cell that is doing the referencing;
$from_name and $to_name are the excel addresses of the same.
$raw.tracinglist created during tracing that forms the backbone of trace_formula. Intended for internal use; $cells and $references contains the important results here.
## Not run: trace_network = trace_formula(path = "NOF material/NOF 2024/NOF 2/Chin1624.xlsx", cell_start = "SPSmrkd!AS20") ## End(Not run)## Not run: trace_network = trace_formula(path = "NOF material/NOF 2024/NOF 2/Chin1624.xlsx", cell_start = "SPSmrkd!AS20") ## End(Not run)
Confirm object is dataframe
validate_data_frame( x, ..., arg = rlang::caller_arg(x), call = rlang::caller_env() )validate_data_frame( x, ..., arg = rlang::caller_arg(x), call = rlang::caller_env() )
x |
Object to check |
... |
additional arguments |
arg |
name of argument in calling function, identified programmatically using rlang |
call |
name of calling function, identified programmatically using rlang |