Build Status codecov GitHub release CRAN Status CRAN Monthly CRAN Total License-blue.svg)

ICES Logo

icesSAG

icesSAG provides R functions that access the web services of the ICES Stock Assessment Graphs database.

icesSAG is implemented as an R package and available on CRAN.

Installation

icesSAG can be installed from CRAN using the install.packages command:

install.packages("icesSAG")

Usage

For a summary of the package:

library(icesSAG)
?icesSAG

Examples

options(icesSAG.messages = FALSE)
options(icesSAG.use_token = FALSE)
library(icesSAG)
library(ggplot2)

To download the summary data for all sandeel stocks published in 2018 use:

summary_data <- getSAG(stock = "sandeel", year = 2018)
head(summary_data)
ggplot(summary_data[complete.cases(summary_data[c("Year", "recruitment")]),], 
       aes(x=Year, y=recruitment, group = fishstock, colour = fishstock)) +
    geom_line()

verbose web service calls

If you want to see all the web service calls being made set this option

options(icesSAG.messages = TRUE)

The result will be

codKeys <- findAssessmentKey("cod", year = 2017)

which allows you to investigate the actual web service data if you are interested: http://sg.ices.dk/StandardGraphsWebServices.asmx/getListStocks?year=2017

Authorised access via tokens

ICES provides public access to the results of published stock assessments. If you are an ICES stock assessor and wish to access unpublished results, or to upload your results, this can be done using token authentication.

You can generate a token from sg.ices.dk/manage/CreateToken.aspx, which will be something like e9351534-20ac-4ad4-9752-98923e011213

Then create a file with the following contents (substitute the access token with your own)

# Standard Graphs personal access token
SG_PAT=e9351534-20ac-4ad4-9752-98923e011213

this should be saved in your home directory in a file called .Renviron_SG.

A quick way to do this from R is

cat("# Standard Graphs personal access token",
    "SG_PAT=e9351534-20ac-4ad4-9752-98923e011213",
    sep = "\n",
    file = "~/.Renviron_SG")

Once you have created this file, you should be able to access unpublished results and upload data to the SAG database. To switch to using authorised access run set the following flag

options(icesSAG.use_token = TRUE)

uploading data

To upload the results of a stock assessment to SAG you must provide two pieces of information, Stock information, such as stock code, assessment year and reference points, and yearly results, such as landings and estimated fishing mortality. There are two helper functions to create the required objects.

stockInfo()

returns a list (it requires a stock code, assessment year and contact email as a minimum), with the correctly named elements. And,

stockFishdata()

returns a data.frame (it requires year as default) with the correctly named columns

A simple (almost) minimal example is:

options(icesSAG.messages = FALSE)
info <- stockInfo("whb-comb", 1996, "colin.millar@ices.dk", Purpose = "")
fishdata <- stockFishdata(1950:1996)

# simulate some landings for something a bit intesting
set.seed(1232)
fishdata$Landings <- 10^6 * exp(cumsum(cumsum(rnorm(nrow(fishdata), 0, 0.1))))

key <- icesSAG::uploadStock(info, fishdata)
key <- 10081

You can check that the data was uploaded by searching for our stock. Note you will need to make sure the icesSAG.use_token option is set to TRUE

options(icesSAG.use_token = TRUE)
findAssessmentKey('whb-comb', 1996, full = TRUE)

We can also look at the landings graph created from the data that were uploaded

plot(getLandingsGraph(key))

References

ICES Stock Assessment Graphs database: http://sg.ices.dk

ICES Stock Assessment Graphs web services: http://sg.ices.dk/webservices.aspx

Development

icesSAG is developed openly on GitHub.

Feel free to open an issue there if you encounter problems or have suggestions for future versions.

The current development version can be installed using:

library(devtools)
install_github("ices-tools-prod/icesSAG")


ices-tools-prod/icesSAG documentation built on Nov. 24, 2023, 1:55 a.m.