Package 'icesSAG'

Title: Stock Assessment Graphs Database Web Services
Description: R interface to access the web services of the ICES Stock Assessment Graphs database <https://sg.ices.dk>.
Authors: Colin Millar [aut, cre], Scott Large [aut], Arni Magnusson [aut], Carlos Pinto [aut], Laura Andreea Petre [aut]
Maintainer: Colin Millar <[email protected]>
License: GPL (>= 2)
Version: 1.5.0
Built: 2024-10-24 09:15:04 UTC
Source: https://github.com/ices-tools-prod/icesSAG

Help Index


Stock Assessment Graphs Database Web Services

Description

R interface to access the web services of the ICES Stock Assessment Graphs database.

Details

Get dataset:

getSummaryTable summary results
getFishStockReferencePoints reference points
getSAG any data

Look up codes:

findAssessmentKey find assessment key
getListStocks list of stocks

Author(s)

Colin Millar, Scott Large, Arni Magnusson, Carlos Pinto and Laura Andreea Petre.

References

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

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

See Also

Useful links:


Create and read the SAG XML data transfer file

Description

Convert between R data (a list and a data.frame) and the XML format required for uploading data to the SAG database.

Usage

createSAGxml(info, fishdata)

readSAGxml(file)

Arguments

info

a list of stock information

fishdata

a data frame of fish data

file

an xml file name

Value

Either a list containing info and fishdata, or a string containing the xml file.

See Also

stockInfo creates a list of stock information.

stockFishdata creates a data frame of fish stock summary data.

Examples

info <- stockInfo(StockCode = "cod.27.347d",
                  AssessmentYear = 2017,
                  StockCategory = 1,
                  ModelType = "A",
                  ModelName = "SCA",
                  ContactPerson = "[email protected]")
fishdata <- stockFishdata(Year = 1990:2017, Catches = 100)
xmlfile <- createSAGxml(info, fishdata)

out <- readSAGxml(xmlfile)

Find a Key

Description

Find a lookup key corresponding to a stock in a given assessment year.

Usage

findAssessmentKey(
  stock = NULL,
  year = 0,
  published = TRUE,
  regex = TRUE,
  full = FALSE
)

Arguments

stock

a stock name, e.g. cod-347d, or cod to find all cod stocks, or NULL (default) to process all stocks.

year

the assessment year, e.g. 2015, or 0 to process all years.

published

whether to include only years where status is "Published" (applies only when non-secure web services are in use, secure web service always returns unpublished stocks).

regex

whether to match the stock name as a regular expression.

full

whether to return a data frame with all stock list columns.

Value

A vector of keys (default) or a data frame if full is TRUE.

Author(s)

Arni Magnusson and Colin Millar.

See Also

getListStocks gets a list of stocks.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
findAssessmentKey("had.27.46a20", 2023, full = TRUE)

## End(Not run)

Get the Custom Columns for SAG records

Description

Get custom columns, such as alternative biomass series or Fproxy reference points for records in the SAG database.

Usage

getCustomColumns(assessmentKey, ...)

Arguments

assessmentKey

the unique identifier of the stock assessment

...

arguments passed to ices_get.

Value

A data frame.

Author(s)

Colin Millar.

See Also

getSAG supports querying many years and quarters in one function call.

getListStocks and getFishStockReferencePoints get a list of stocks and reference points.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
assessmentKey <- findAssessmentKey("bli.27.5a14")
customs <- getCustomColumns(assessmentKey)
head(customs)

## End(Not run)

Get Reference Points

Description

Get biological reference points for all stocks in a given assessment year.

Usage

getFishStockReferencePoints(assessmentKey, ...)

Arguments

assessmentKey

the unique identifier of the stock assessment

...

arguments passed to ices_get.

Value

A data frame.

Author(s)

Colin Millar.

See Also

getSAG supports querying many years and quarters in one function call.

getListStocks and getSummaryTable get a list of stocks and summary results.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
assessmentKey <- findAssessmentKey("cod.27.21", year = 2023)
refpts <- getFishStockReferencePoints(assessmentKey)
refpts

# To get all reference points in a given assessment year:
keys2022 <- findAssessmentKey(year = 2022, full = TRUE)
keys2022 <- keys2022[keys2022$Purpose == "Advice",]
refpts2022 <- getFishStockReferencePoints(keys2022$AssessmentKey)
refpts2022

## End(Not run)

Get List of Most Recent Advice

Description

Get a list of the most recent advice for all fish stocks.

Usage

getLatestStockAdviceList(...)

Arguments

...

arguments passed to ices_get.

Value

A data frame.

Author(s)

Colin Millar, Scott Large, and Arni Magnusson.

See Also

getSummaryTable gets a summary table of historical stock size.

getFishStockReferencePoints gets biological reference points.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
stocks <- getLatestStockAdviceList()

## End(Not run)

Get a List of Fish Stocks

Description

Get a list of fish stocks for a given assessment year.

Usage

getListStocks(year, stock = NULL, modifiedAfter = NULL, ...)

Arguments

year

the assessment year, e.g. 2015, or 0 to process all years.

stock

a stock name, e.g. lin.27.5a.

modifiedAfter

date-time parameter in the format "YYYY/MM/DD". If set will only return stocks assessments modified after the provided date.

...

arguments passed to ices_get.

Value

A data frame.

Author(s)

Colin Millar.

See Also

getSummaryTable gets a summary table of historical stock size.

getFishStockReferencePoints gets biological reference points.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
stocks <- getListStocks(2023)
nshad <- getListStocks(stock = "had.27.46a20")

## End(Not run)

Get Any SAG Data

Description

This function combines the functionality of getListStocks, getFishStockReferencePoints, getSummaryTable and getStockDownloadData. It supports querying many stocks and years in one function call.

Usage

getSAG(stock, year, data = "summary", combine = TRUE, purpose = "Advice")

Arguments

stock

a stock name, e.g. cod-347d, or cod to find all cod stocks, or NULL to process all stocks.

year

the assessment year, e.g. 2015, or 0 to process all years.

data

the data of interest, either "summary", "refpts" or "source".

combine

whether to combine the list output to a data frame.

purpose

the purpose of the entry, options are "Advice", "Bench", "InitAdvice", default is "Advice".

Value

A data frame (default) or a list if combine is TRUE.

Note

Only years with "Published" status are returned.

Author(s)

Colin Millar.

See Also

getListStocks, getSummaryTable, getFishStockReferencePoints, and getStockDownloadData get a list of stocks, summary results, reference points, and all data including custom columns.

findAssessmentKey finds lookup keys.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
summary <- getSAG("had.27.46a20", 2022)
refpts <- getSAG("had.27.46a20", 2022, "refpts")

cod_summary <- getSAG("cod", 2022)
cod_refpts <- getSAG("cod", 2015:2016, "refpts")
cod_data <- getSAG("cod", 2017, "source-data")

## End(Not run)

Get Summary Graphs of Stock Assessment Output

Description

Get summary graphs of catches, recruitment, fishing pressure, and spawning stock biomass.

Usage

getSAGGraphs(assessmentKey, ...)

Arguments

assessmentKey

the unique identifier of the stock assessment

...

to allow scope for back compatibility

Value

An array representing a bitmap.

Author(s)

Colin Millar and Scott Large.

See Also

getListStocks gets a list of stocks.

getFishStockReferencePoints gets biological reference points.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
assessmentKey <- findAssessmentKey("cod", 2015)
graphs <- getSAGGraphs(assessmentKey[1])
plot(graphs)
# note this stock only has one graph see:
# http://standardgraphs.ices.dk/ViewCharts.aspx?key=8309

## End(Not run)

Get Details on SAG Charts and Settings

Description

List all possible chart settings for each chart type (0 = general, 1 = Landings, ...).

Usage

getSAGTypeGraphs(...)

getSAGTypeSettings(SAGChartKey, ...)

Arguments

...

arguments passed to ices_get.

SAGChartKey

the type identifier of the SAG chart, e.g. 0, 1, 2, ...

Value

a data frame with SAG chart type IDs and settings IDs.

Examples

## Not run: 
getSAGTypeGraphs()

getSAGTypeSettings(0)[-4]

## End(Not run)

Get and Set SAG Chart Settings

Description

details

Usage

getSAGSettingsForAStock(assessmentKey, ...)

setSAGSettingForAStock(
  assessmentKey,
  chartKey,
  settingKey,
  settingValue,
  copyNextYear,
  ...
)

Arguments

assessmentKey

the unique identifier of the stock assessment

...

arguments passed to ices_get.

chartKey

the type identifier of the SAG chart, e.g. 0, 1, 2, ...

settingKey

the type identifier of the SAG chart setting, e.g. 0, 1, 2, ...

settingValue

the vale of the setting

copyNextYear

should the settings be copied to next year (TRUE) or not (FALSE)

Value

A data frame with SAG chart type IDs, settings IDs and setting values.

Examples

## Not run: 
key <- findAssessmentKey("cod.21.1", 2017)
graphs <- getSAGGraphs(key[1])
plot(graphs)
getSAGSettingsForAStock(key [1])
chart1 <- getLandingsGraph(key [1])
setSAGSettingForAStock(key [2], 1, 1, "Catches of cod.21.1 in 2017",
FALSE)
setSAGSettingForAStock(key [2], 1, 11, 10,
FALSE)
plot(chart1)
chart2 <- getSpawningStockBiomassGraph(key [1])
plot(chart2)
setSAGSettingForAStock(key [1], 4, 1, "SSB of cod.21.1 in 2017",
FALSE)
plot(chart2)

## End(Not run)

Get a Graph of Stock Assessment Output

Description

Get a graph of stock assessment output, e.g., historical stock size, recruitment, and fishing pressure.

Usage

getLandingsGraph(assessmentKey, ...)

getRecruitmentGraph(assessmentKey, ...)

getFishingMortalityGraph(assessmentKey, ...)

getSpawningStockBiomassGraph(assessmentKey, ...)

getFishMortality(assessmentKey, ...)

getstock_recruitment(assessmentKey, ...)

getYSSB(assessmentKey, ...)

getSSBHistoricalPerformance(assessmentKey, ...)

getFishingMortalityHistoricalPerformance(assessmentKey, ...)

getRecruitmentHistoricalPerformance(assessmentKey, ...)

getStockStatusTable(assessmentKey, ...)

Arguments

assessmentKey

the unique identifier of the stock assessment

...

to allow scope for back compatibility

Value

An array representing a bitmap.

See Also

getListStocks gets a list of stocks.

getFishStockReferencePoints gets biological reference points.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
assessmentKeys <- findAssessmentKey("had", 2015)
landings_img <- getLandingsGraph(assessmentKeys[1])
plot(landings_img)

landings_plots <- getLandingsGraph(assessmentKeys)
plot(landings_plots)

## End(Not run)

Get Source Data

Description

Get a copy of the source data for the specified stocks.

Usage

getStockDownloadData(assessmentKey, ...)

Arguments

assessmentKey

the unique identifier of the stock assessment, can be a vector

...

arguments passed to ices_get.

Value

A data frame.

Author(s)

Colin Millar.

See Also

getSAG supports querying many years in one function call.

getListStocks and getFishStockReferencePoints get a list of stocks and reference points.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
assessmentKey <- findAssessmentKey("cod-2224", year = 2016)
sourcedat <- getStockDownloadData(assessmentKey)
head(sourcedat[[1]])

## End(Not run)

Get the Values in a Stock Status Table

Description

Get summary results of historical stock size, recruitment, and fishing pressure.

Usage

getStockStatusValues(assessmentKey, ...)

Arguments

assessmentKey

the unique identifier of the stock assessment

...

arguments passed to ices_get.

Value

A data frame.

Author(s)

Colin Millar.

See Also

getSAG supports querying many years and quarters in one function call.

getListStocks and getFishStockReferencePoints get a list of stocks and reference points.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
assessmentKey <- findAssessmentKey("had.27.46a20", year = 2022)
status <- getStockStatusValues(assessmentKey)
status

## End(Not run)

Get a Summary Table of Historical Stock Size

Description

Get summary results of historical stock size, recruitment, and fishing pressure.

Usage

getSummaryTable(assessmentKey, ...)

Arguments

assessmentKey

the unique identifier of the stock assessment

...

arguments passed to ices_get.

Value

A data frame.

Author(s)

Colin Millar.

See Also

getSAG supports querying many years and quarters in one function call.

getListStocks and getFishStockReferencePoints get a list of stocks and reference points.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
assessmentKey <- findAssessmentKey("had.27.46a20", year = 2022)
sumtab <- getSummaryTable(assessmentKey)
head(sumtab)

## End(Not run)

Get a url

Description

Get a url, optionally using an ICES authentication token

Usage

ices_get(
  url,
  retry = TRUE,
  quiet = !getOption("icesSAG.messages"),
  verbose = FALSE,
  content = TRUE,
  use_token = getOption("icesSAG.use_token")
)

ices_get_cached(
  url,
  retry = TRUE,
  quiet = !getOption("icesSAG.messages"),
  verbose = FALSE,
  content = TRUE,
  use_token = getOption("icesSAG.use_token")
)

Arguments

url

the url to get.

retry

should the get request be retried if first attempt fails? default TRUE.

quiet

should all messages be suppressed, default FALSE.

verbose

should verbose output form the http request be returned? default FALSE.

content

should content be returned, or the full http response? default TRUE, i.e. content is returned by default.

use_token

should an authentication token be sent with the request? default is the value of the option icesSAG.use_token.

Value

content or an http response.

Functions

  • ices_get_cached(): cached version of ices_get

See Also

sag_api builds a SAG web service url.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
ices_get(sag_api("StockList", year = 2022))

## End(Not run)

Post to a url

Description

Post to a url using an ICES authentication token

Usage

ices_post(url, body = list(), retry = TRUE, verbose = FALSE, use_token = TRUE)

Arguments

url

the url to get.

body

a list of named arguments to be sent as the body of the post request.

retry

should the get request be retried if first attempt fails? default TRUE.

verbose

should verbose output form the http request be returned? default FALSE.

use_token

should an authentication token be sent with the request? default is TRUE.

Value

content or an http response.

See Also

sag_api builds a SAG web service url.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
ices_get(sag_api("StockList", year = 2022))

## End(Not run)

Build a SAG web service url

Description

utility to build a url with optional query arguments

Usage

sag_api(service, ...)

Arguments

service

the name of the service

...

name arguments will be added as queries

Value

a complete url as a character string

Examples

sag_api("hi", bye = 21)
sag_api("StockList", year = 2021)

Get and Set icesSAG package options

Description

There are two options of interest, 1) switch on or off the use off authenticated web service calls, and 2) switch on or off the display of messages to the console.

Usage

sag_use_token(value)

sag_messages(value)

Arguments

value

TRUE or FALSE

Value

invisible return of the old value.

Examples

## Not run: 
sag_use_token(TRUE)
sag_messages(TRUE)

## End(Not run)

Create a data.frame of fish stock data

Description

This function is a wrapper to data.frame(...) in which the names are forced to match with the names required for the SAG database. See http://dome.ices.dk/datsu/selRep.aspx?Dataset=126 for more details.

Usage

stockFishdata(Year, ...)

Arguments

Year

a vector of years.

...

additional information, e.g. Recruitment, StockSize, Landings, ...

Value

A data.frame, where all names are valid column names in the SAG database.

Author(s)

Colin Millar.

Examples

stockFishdata(Year = 1990:2017, Catches = 100)

Create a list of fish stock information

Description

This function is a wrapper to list(...) in which the names are forced to match with the names required for the SAG database. See http://dome.ices.dk/datsu/selRep.aspx?Dataset=126 for more details.

Usage

stockInfo(
  StockCode,
  AssessmentYear,
  ContactPerson,
  StockCategory,
  Purpose = "Advice",
  ModelType,
  ModelName,
  ...
)

Arguments

StockCode

a stock name, e.g. cod-347d.

AssessmentYear

the assessment year, e.g. 2015.

ContactPerson

the email for the person responsible for uploading the stock data.

StockCategory

Category of the assessment used (see below)

Purpose

the purpose of the entry, options are "Advice", "Bench", "InitAdvice", default is "Advice".

ModelType

the type of the model used (see below for links to more information)

ModelName

the name (acronym) of the model used if available (see below for links to more information)

...

additional information, e.g. BMGT, FMSY, RecruitmentAge, ...

Value

A named sag.list, inheriting from a list, where all names are valid column names in the SAG database.

Author(s)

Colin Millar.

See Also

Links to the relevant ICES vocabularies list are here StockCode: https://vocab.ices.dk/?ref=357 StockCategory: https://vocab.ices.dk/?ref=1526 Purpose: https://vocab.ices.dk/?ref=1516 ModelType: https://vocab.ices.dk/?ref=1524 ModelName: https://vocab.ices.dk/?ref=1525

Link to the relevant format description is https://datsu.ices.dk/web/selRep.aspx?Dataset=126

Examples

info <-
  stockInfo(StockCode = "cod.27.47d20",
            AssessmentYear = 2017,
            StockCategory = 1,
            ModelType = "A",
            ModelName = "SCA",
            ContactPerson = "[email protected]")

 info
 info$mistake <- "oops"
 info
 # should have gotten a warning message

 ## Not run: 
 # use icesVocab to list valid codes etc.
 library(icesVocab)
 # print the list of valid stock codes
 stock.codes <- getCodeList("ICES_StockCode")
 stock.codes[1:10,1:2]

 # print the list of assessment model types in the ICES vocabulary
 model.types <- getCodeList("AssessmentModelType")
 model.types[1:2]

 # print the list of assessment model names in the ICES vocabulary
 model.names <- getCodeList("AssessmentModelName")
 model.names$Key
 
## End(Not run)