## ----include=FALSE------------------------------------------------------------
nua_available <- tryCatch({
  httr::status_code(httr::GET("https://nordicmicroalgae.org/",
                               httr::timeout(5))) < 400
}, error = function(e) FALSE)

## ----eval=FALSE---------------------------------------------------------------
# install.packages("SHARK4R")

## -----------------------------------------------------------------------------
library(SHARK4R)

## ----include=FALSE, eval=nua_available----------------------------------------
taxa <- try(get_nua_taxa(unparsed = FALSE), silent = TRUE)
if (inherits(taxa, "try-error")) nua_available <- FALSE

## ----eval=FALSE---------------------------------------------------------------
# # Get taxa information
# taxa <- get_nua_taxa(unparsed = FALSE)
# 
# # Print data
# print(taxa)

## ----echo=FALSE, eval=nua_available-------------------------------------------
print(taxa)

## ----include=FALSE, eval=nua_available----------------------------------------
slugs <- sample(taxa$slug, size = 10)
external_links <- try(
  get_nua_external_links(slugs, verbose = FALSE, unparsed = FALSE),
  silent = TRUE
)
if (inherits(external_links, "try-error")) nua_available <- FALSE

## ----eval=FALSE---------------------------------------------------------------
# # Randomly select 10 taxa from shark_taxon$scientific_name
# slugs <- sample(taxa$slug, size = 10)
# 
# # Get external links
# external_links <- get_nua_external_links(slugs,
#                                          verbose = FALSE,
#                                          unparsed = FALSE)
# 
# # Print list
# print(external_links)

## ----echo=FALSE, eval=nua_available-------------------------------------------
print(external_links)

## ----include=FALSE, eval=nua_available----------------------------------------
harmfulness <- try(
  get_nua_harmfulness(c("dinophysis-acuta", "alexandrium-ostenfeldii"),
                      verbose = FALSE),
  silent = TRUE
)
if (inherits(harmfulness, "try-error")) nua_available <- FALSE

## ----eval=FALSE---------------------------------------------------------------
# # Get external links
# harmfulness <- get_nua_harmfulness(c("dinophysis-acuta",
#                                      "alexandrium-ostenfeldii"),
#                                    verbose = FALSE)
# 
# # Print list
# print(harmfulness)

## ----echo=FALSE, eval=nua_available-------------------------------------------
print(harmfulness)

## ----include=FALSE, eval=nua_available----------------------------------------
media <- try(get_nua_media_links(unparsed = FALSE), silent = TRUE)
if (inherits(media, "try-error")) nua_available <- FALSE

## ----eval=FALSE---------------------------------------------------------------
# # Get all media links
# media <- get_nua_media_links(unparsed = FALSE)
# 
# # Print list
# print(media)

## ----echo=FALSE, eval=nua_available-------------------------------------------
print(media)

## ----include=FALSE, eval=nua_available----------------------------------------
media_metadata <- try(get_nua_media_metadata(unparsed = FALSE), silent = TRUE)
if (inherits(media_metadata, "try-error")) nua_available <- FALSE

## ----eval=FALSE---------------------------------------------------------------
# # Get all media metadata
# media_metadata <- get_nua_media_metadata(unparsed = FALSE)
# 
# # Print list
# print(media_metadata)

## ----echo=FALSE, eval=nua_available-------------------------------------------
print(media_metadata)

## ----include=FALSE, eval=nua_available----------------------------------------
il_links <- try(get_nua_image_labeling_links(unparsed = FALSE), silent = TRUE)
if (inherits(il_links, "try-error")) nua_available <- FALSE

## ----eval=FALSE---------------------------------------------------------------
# # Get all image labeling media links
# il_links <- get_nua_image_labeling_links(unparsed = FALSE)
# 
# # Print list
# print(il_links)

## ----echo=FALSE, eval=nua_available-------------------------------------------
print(il_links)

## ----include=FALSE, eval=nua_available----------------------------------------
il_metadata <- try(
  get_nua_image_labeling_metadata(unparsed = FALSE),
  silent = TRUE
)
if (inherits(il_metadata, "try-error")) nua_available <- FALSE

## ----eval=FALSE---------------------------------------------------------------
# # Get all image labeling metadata
# il_metadata <- get_nua_image_labeling_metadata(unparsed = FALSE)
# 
# # Print list
# print(il_metadata)

## ----echo=FALSE, eval=nua_available-------------------------------------------
print(il_metadata)

## ----include=FALSE, eval=nua_available----------------------------------------
peg_list <- try(get_peg_list(), silent = TRUE)
nomp_list <- try(get_nomp_list(), silent = TRUE)
peg_ok <- !inherits(peg_list, "try-error")
nomp_ok <- !inherits(nomp_list, "try-error")

## ----eval=FALSE---------------------------------------------------------------
# # Get EG Phyto Biovolume list
# peg_list <- get_peg_list()
# 
# # Print list
# print(peg_list)
# 
# # Get NOMP Biovolume list
# nomp_list <- get_nomp_list()
# 
# # Print list
# print(nomp_list)

## ----echo=FALSE, eval=nua_available && peg_ok---------------------------------
print(peg_list)

## ----echo=FALSE, eval=nua_available && nomp_ok--------------------------------
print(nomp_list)

## ----echo=FALSE---------------------------------------------------------------
# Print citation
citation("SHARK4R")

## ----echo=FALSE---------------------------------------------------------------
clean_shark4r_cache(0, clear_perm_cache = TRUE, verbose = FALSE)

