| Title: | Functions for processing ICES data and producing ICES shiny applications |
|---|---|
| Description: | A collection of functions useful for processing ICES data and making ICES shiny apps. |
| Authors: | Colin Millar [aut, cre], Luca Lamoni [aut], Neil Maginnis [aut] |
| Maintainer: | Colin Millar <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.3 |
| Built: | 2026-05-28 06:31:13 UTC |
| Source: | https://github.com/ices-tools-dev/icesUtils |
A collection of functions useful for processing ICES data and making ICES shiny apps.
Group of functions:
first_function |
example function |
Maintainer: Colin Millar [email protected]
Authors:
Luca Lamoni
Neil Maginnis
ICES Stock Assessment Graphs database: http://sg.ices.dk.
ICES Stock Assessment Graphs web services: http://sg.ices.dk/webservices.aspx.
Useful links:
Report bugs at https://github.com/ices-tools-dev/icesUtils/issues
Find the summary data for a specific stock in a given assessment year.
first_function(stock, year)first_function(stock, year)
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. |
This function retrieves summary data for a specified stock and year from the SAG and SD Databases. It first validates the stock code against the ICES vocabulary database, then fetches stock information from the Stock Data (SD) database, and the summary table data from the Stock Assessment Graphs (SAG) database.
The results from both sources are combined into a single dataframe which is returned to the user.
A dataframe.
Colin Millar.
getSAG gets summary table from SAG DB.
icesSAG-package gives an overview of the icesSAG package.
icesUtils-package gives an overview of the icesUtils package.
assessment_summary <- first_function("had.27.46a20", 2023) head(assessment_summary)assessment_summary <- first_function("had.27.46a20", 2023) head(assessment_summary)
Queries the ICES bycatch API and returns the bycatch advice results for a specified ecoregion.
get_bycatch_ecoregion(Ecoregion)get_bycatch_ecoregion(Ecoregion)
Ecoregion |
A character string giving the ecoregion name to be passed to the ICES bycatch API. |
This function builds the API request URL using the supplied ecoregion name, URL-encodes it, and parses the JSON response with 'jsonlite::fromJSON()'.
It does not perform validation of the API response, so downstream cleaning is usually needed before plotting or analysis.
A data frame or list, depending on the API response structure, containing bycatch advice results for the requested ecoregion.
## Not run: bycatch_raw <- get_bycatch_ecoregion("Greater North Sea") ## End(Not run)## Not run: bycatch_raw <- get_bycatch_ecoregion("Greater North Sea") ## End(Not run)
Adds a JavaScript handler that lets users click on an image to enter/exit fullscreen
image_fullscreen_on_click_js()image_fullscreen_on_click_js()
A script tag containing JavaScript code.
if (requireNamespace("shiny", quietly = TRUE) && interactive()) { library(shiny) addResourcePath( "mypkg", system.file("www", package = "icesUtils") ) ui <- navbarPage( header = image_fullscreen_on_click_js(), title = "Example", "Click for full screen", tags$img(src = "mypkg/example-image.png", id = "demo-img", width = "300px", height = "300px") ) server <- function(input, output, session) {} shinyApp(ui, server) }if (requireNamespace("shiny", quietly = TRUE) && interactive()) { library(shiny) addResourcePath( "mypkg", system.file("www", package = "icesUtils") ) ui <- navbarPage( header = image_fullscreen_on_click_js(), title = "Example", "Click for full screen", tags$img(src = "mypkg/example-image.png", id = "demo-img", width = "300px", height = "300px") ) server <- function(input, output, session) {} shinyApp(ui, server) }
Uses prepare_text_from_excel to make a nested list containing text
content extractable by section. Requires that paths and
names are vectors of equal length.
Output works with select_text where names gives the
top_level parameter to select_text. vector of names an excel file into a list of dataframes. Works with usethis::use_data and
select_text to provide a simple means of incorporating text in shiny applications.
To work with usethis::use_data the excel file should have named tabs,
prepare_nested_text_lists_from_excel(paths, names)prepare_nested_text_lists_from_excel(paths, names)
paths |
valid paths provided either as vector or list |
names |
list or vector of characters |
prepare_text_from_excel converts texts provided via
a single excel file into a structure that select_text can work with. Used by this function on each file provided.
select_text extracts individual texts by tab,
section and, optionally, top-level names.
Converts an excel file into a list of dataframes. Works with usethis::use_data and
select_text to provide a simple means of incorporating text in shiny applications.
To work with usethis::use_data the excel file should have named tabs,
each tab having 2 columns, section and text. text is the content,
section is used by select_text to extract the relevant section.
Texts provided in text are wrapped in the HTML paragraph tag <p>.
prepare_text_from_excel(path_to_file)prepare_text_from_excel(path_to_file)
path_to_file |
path to the file containing text content |
a list of dataframes
prepare_nested_text_lists_from_excel converts texts
in multiple files into a hierarchical structure that select_text can work with.
select_text extracts individual texts by tab,
section and, optionally, top-level names.
example_path <- system.file("extdata", "text_function_example.xlsx", package = "icesUtils") prepare_text_from_excel(path_to_file = example_path)example_path <- system.file("extdata", "text_function_example.xlsx", package = "icesUtils") prepare_text_from_excel(path_to_file = example_path)
display_text´ subsets a list of dataframes and extracts the relevant section of text for tab and section If top_level is supplied, accepts a named list of lists, and filters the top level list by top_level name.
select_text(list_of_texts, tab, section = NULL)select_text(list_of_texts, tab, section = NULL)
list_of_texts |
a list of dataframes each containing 'section' and 'text' columns |
tab |
a character vector - the name of a list entry |
section |
a character vector indicating which row to extract |
A character string
Neil Maginnis
prepare_text_from_excel is a function that converts texts provided via an excel file into a structure that select_text can work with.
prepare_nested_text_lists_from_excel converts texts in multiple files into a hierarchical structure that select_text can work with.
greetings <- data.frame(section = c("welcome", "goodbye"), text = c("Hello world", "Thanks for stopping by")) content <- data.frame(section = "help", text = "Use the function as shown here") texts <- list(greetings=greetings, content = content) select_text(list_of_texts = texts, "greetings", "welcome") select_text(list_of_texts = texts, "content", "help") select_text(list_of_texts = texts, "greetings", "goodbye")greetings <- data.frame(section = c("welcome", "goodbye"), text = c("Hello world", "Thanks for stopping by")) content <- data.frame(section = "help", text = "Use the function as shown here") texts <- list(greetings=greetings, content = content) select_text(list_of_texts = texts, "greetings", "welcome") select_text(list_of_texts = texts, "content", "help") select_text(list_of_texts = texts, "greetings", "goodbye")