Running a TAF analysis - ices-taf/doc GitHub Wiki
See also: Creating a TAF analysis.
This page was based on using the icesTAF
package version 4.2.0
dated
2023-03-21
.
In this guide
Finding an analysis
The first step is finding a TAF analysis that you want to run. All TAF stock assessments are made available on the TAF web application (see screenshot below). There are publicly avilable analyses and private ones. Private analyses have not yet been made publicly available and require to be reviewed. Public analyses are accessed by clicking the “see publlic demo” button, and private analyses are accessed by clicking the “Manage stock assessments” button - this is only available to logged in users of the ICES network and specifically to members of ICES stock assessment working groups.
In the following example we will select the 2019 sandeel in area 6
assessment, and the application gives a link to the github repository
for the code as
github.com/ices-taf/2019_san.sa.6
.
as seen below:
Getting the code
From the previous section we have found the github address of the code
we want to run, however we only need the name of the repository which
is: ices-taf/2019_san.sa.6
. The following code will download the code
into a directory that you specify, otherwise it will download into a
temporary directory on your computer (default). In this case we will
choose the current working directory (specified by "."
) that your R
sessions is running in (see getwd()
to find out what this is).
run_dir <- download.analysis("ices-taf/2019_san.sa.6", dir = ".")
## repo: ices-taf/2019_san.sa.6 has been downloaded to: .
which results in the following files and directories:
.
°--2019_san.sa.6-20230530-122740
¦--bootstrap
¦ ¦--DATA.bib
¦ °--initial
¦ °--data
¦ °--sandeel_assessment_1982_2018.csv
¦--data.R
¦--output.R
¦--report.R
¦--report.Rmd
¦--report_doc.R
¦--report_plots.R
¦--report_tables.R
°--utilities.R
Running the code
There are three steps to running a TAF analysis. All these steps are
contained in the function run.analysis()
, but for the sake of
explaition, we will present each in turn, before showing the two lines
of code you need to run in the Rounding up section.
- install all relavant packages:
install.deps()
- run the data and software boot procedure:
taf.boot()
- run the TAF analysis scripts:
sourceAll()
install.deps()
1. install all relavant packages: Some analyses may use R packages that are widely available but that you
do not have installed on your own computer. The deps()
function
provides a list of packages used in an analysis, for example in the
example we are working with we have:
deps(run_dir)
## [1] "captioner" "dplyr" "ggplot2" "htmlTable" "icesSAG" "icesTAF" "knitr" "pander" "rmarkdown" "tidyr"
and the following function installs all of those packages that you do not have installed
install.deps(run_dir)
taf.boot()
2. run the data and software boot procedure: the next step is to run taf.boot()
. But before we do this we need to
set the working direcory to the location of the TAF scripts. Note here
that the function setwd()
returns the current working directory so we
can return to where we were when we are finished.
oldwd <- setwd(run_dir)
taf.boot()
## [12:27:42] Boot procedure running...
## Processing DATA.bib
## [12:27:42] * reportTemplate.docx
## [12:27:42] * sandeel_assessment_1982_2018.csv
## [12:27:42] Boot procedure done
setwd(oldwd)
which gathers data and software specified in the DATA.bib
and
SOFTWARE.bib
files, and results in the following
.
°--2019_san.sa.6-20230530-122740
¦--bootstrap
¦ ¦--data
¦ ¦ ¦--reportTemplate.docx
¦ ¦ °--sandeel_assessment_1982_2018.csv
¦ ¦--DATA.bib
¦ °--initial
¦ °--data
¦ °--sandeel_assessment_1982_2018.csv
¦--data.R
¦--output.R
¦--report.R
¦--report.Rmd
¦--report_doc.R
¦--report_plots.R
¦--report_tables.R
°--utilities.R
notice that there is a new folder boot/data
which contains files that
can now be used by the TAF analysis scripts in the next section.
sourceAll()
3. run the TAF analysis scripts: The final step is to run sourceAll()
, which runs, in sequence, the
data.R
, model.R
, output.R
and report.R
scripts.
oldwd <- setwd(run_dir)
sourceAll()
## Error in stockInfo(StockCode = "san.sa.6", AssessmentYear = 2019, ContactPerson = "[email protected]", :
## argument "StockCategory" is missing, with no default
## 1/14
## 2/14 [libraries]
## 3/14
## 4/14 [chunk_setup]
## 5/14
## 6/14 [pander_settings]
## 7/14
## 8/14 [caption_counters]
## 9/14
## 10/14 [catch_table]
## 11/14
## 12/14 [catch_plot]
## 13/14
## 14/14 [catch_plot2]
## "C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS report.knit.md --to docx --from markdown+autolink_bare_uris+tex_math_single_backslash --output report.docx --lua-filter "C:\Users\colin\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\pagebreak.lua" --table-of-contents --toc-depth 3 --highlight-style tango --reference-doc "bootstrap\data\reportTemplate.docx"
setwd(oldwd)
and gives us the complete output from the TAF analyses.
.
°--2019_san.sa.6-20230530-122740
¦--bootstrap
¦ ¦--data
¦ ¦ ¦--reportTemplate.docx
¦ ¦ °--sandeel_assessment_1982_2018.csv
¦ ¦--DATA.bib
¦ °--initial
¦ °--data
¦ °--sandeel_assessment_1982_2018.csv
¦--data
¦ °--summary_catch.csv
¦--data.R
¦--output
¦--output.R
¦--report
¦ ¦--catches_by_halfyear_bar.png
¦ ¦--catches_by_halfyear_stack.png
¦ ¦--report.docx
¦ ¦--summary_catch.csv
¦ ¦--summary_catch.html
¦ °--summary_catch.png
¦--report.R
¦--report.Rmd
¦--report_doc.R
¦--report_plots.R
¦--report_tables.R
°--utilities.R
Rounding up
The files in the TAF analyses we have just run should the same as on the TAF web application page. Differences can occur in some more complicated analyses, and this is to be expected with differences in software between different machines.
All together, to get and run a TAF analysis stored on a GitHub reposuitory, run the following lines of code in R:
# get code
run_dir <- download.analysis("ices-taf/2019_san.sa.6", dir = ".")
# run analysis
run.analysis(run_dir)