REPRODUCIBILITY {#app:reproducibility}

One goal of this report is to generate standardized data sets, model fits, and visualizations to facilitate stock assessment. We intend for the data extraction and plots developed here to be useful for the upcoming management-procedure framework for data-limited and data-moderate groundfish stocks in BC, and also for the preparation of other groundfish stock assessments and to facilitate data-to-document workflows that go straight from databases to the final report via code and can be quickly updated in future years. To that end, the data extraction, data manipulation, model fitting, and visualization for this report are automated.

get_sha <- function(path) {
  suppressWarnings({
    sha <- tryCatch(system(paste0("git ls-remote git@github.com:", path, ".git"),
      intern = TRUE, ignore.stderr = TRUE), error = function(e) " ")
  })
  if (is.null(attr(sha, "status")))
    substr(sha[grepl("HEAD", sha)], 1, 7)
  else
    "xxxxxxx"
}
sha_gfplot <- get_sha("pbs-assess/gfplot")
sha_gfiphc <- get_sha("pbs-assess/gfiphc")
sha_gfdata <- get_sha("pbs-assess/gfdata")
sha_gfsynopsis <- get_sha("pbs-assess/gfsynopsis")
sha_sdmTMB <- get_sha("pbs-assess/sdmTMB")
sha_csasdown <- get_sha("pbs-assess/csasdown")

The data extraction was accomplished with the gfdata R package Git SHA (Secure Hash Algorithm) r sha_gfdata; model fitting and plots were accomplished with the gfplot R package (figure \@ref(fig:gfplot-web)) Git SHA r sha_gfplot. The spatial and spatiotemporal models were fit with the sdmTMB package Git SHA r sha_sdmTMB. The IPHC survey index calculations were performed with the gfiphc package Git SHA r sha_gfiphc. The plots were assembled on figure pages and this text was written with the package gfsynopsis Git SHA r sha_gfsynopsis. The document was compiled with the csasdown package Git SHA version r sha_csasdown.

The specific versions used to generate this report can be viewed at:

<r paste0("https://github.com/pbs-assess/gfdata/tree/", sha_gfdata)>\ <r paste0("https://github.com/pbs-assess/gfplot/tree/", sha_gfplot)>\ <r paste0("https://github.com/pbs-assess/sdmTMB/tree/", sha_sdmTMB)>\ <r paste0("https://github.com/pbs-assess/gfiphc/tree/", sha_gfiphc)>\ <r paste0("https://github.com/pbs-assess/gfsynopsis/tree/", sha_gfsynopsis)>\ <r paste0("https://github.com/pbs-assess/csasdown/tree/", sha_csasdown)>\

\vspace{4mm} or installed via:

devtools::install_github('pbs-assess/gfdata', ref = 'r sha_gfdata')\ devtools::install_github('pbs-assess/gfplot', ref = 'r sha_gfplot')\ devtools::install_github('pbs-assess/sdmTMB', ref = 'r sha_sdmTMB')\ devtools::install_github('pbs-assess/gfiphc', ref = 'r sha_gfiphc')\ devtools::install_github('pbs-assess/gfsynopsis', ref = 'r sha_gfsynopsis')\ devtools::install_github('pbs-assess/csasdown', ref = 'r sha_csasdown')\

\vspace{4mm} Copies of these R package versions and a copy of the cached data will be archived on a local Pacific Biological Station server to ensure future reproducibility.

Our functions dynamically scrape COSEWIC and SARA status information from the Species at risk public registry with rvest [@rvest2016] and join it to the species list by scientific name. We scrape taxonomic information from the Integrated Taxonomic Information System (ITIS) with the taxize package [@chamerberlain2013].

The figure pages can be built while on the PBS network by (1) installing the above packages, (2) cloning the gfsynopsis repository, and (3) following instructions found in the gfsynopsis README.md file.

The master function is gfsynopsis::make_pages(), which generates two .png files comprising the two pages of plots for each species. Within this function, individual plots are generated by gfplot as ggplot objects [@ggplot2] and ggplot 'Grobs' are laid out on each page using the packages egg [@egg] and gridExtra [@gridExtra]. gfplot draws heavily on the R 'tidyverse', and especially dplyr [@dplyr].

This report can then be rendered using knitr [@knitr], bookdown [@bookdown], and csasdown by running:

bookdown::render_book("index.Rmd")

from the gfsynopsis/report/report-rmd folder or by clicking the 'Knit' button in RStudio with report/report-rmd/index.Rmd open.

This version of the document was generated on r Sys.time() with r devtools::session_info()$platform$version [@r2018] and R package versions:

suppressWarnings({suppressMessages({
  library(TMB)
  library(rstan)
  library(bookdown)
  library(rmarkdown)
  library(gfsynopsis)
  library(sdmTMB)
  library(INLA)
  library(knitr)
  library(gridExtra)
  library(PBSmapping)
  library(PBSdata)
  library(taxize)
  library(rvest)
  library(egg)
})})
pkgs <- sort(c("gfplot", "ggplot2", "dplyr", "rstan", "knitr", "glmmTMB",
  "TMB", "broom.mixed", "purrr", "kableExtra",
  "csasdown", "bookdown", "rmarkdown", "INLA", "sdmTMB", "gfsynopsis",
  "PBSdata", "PBSmapping", "egg", "gridExtra", "rvest", "egg"))
devtools::session_info()$packages %>%
  dplyr::filter(package %in% pkgs) %>%
  dplyr::select(package, loadedversion, date) %>%
  dplyr::rename(Package = package, Version = loadedversion, Date = date) %>%
  csasdown::csas_table()

r functions extract raw data from the relational databases, \\texttt{tidy} and \\texttt{fit} functions manipulate the data or fit statistical models, and \\texttt{plot} functions take the output from the tidying or fitting functions to make visualizations.", out.width="4.2in"} knitr::include_graphics(here::here("report", "report-rmd", "figure", "function-web.pdf"), dpi = NA)

\clearpage



pbs-assess/gfsynopsis documentation built on March 26, 2024, 7:30 p.m.