Learn R Programming

SHARK4R (version 1.0.2)

get_shark_codes: Get SHARK codelist from SMHI

Description

This function downloads the SHARK codes Excel file from SMHI (if not already cached) and reads it into R. The file is stored in a persistent cache directory so it does not need to be downloaded again in subsequent sessions.

Usage

get_shark_codes(
  url =
    "https://smhi.se/oceanografi/oce_info_data/shark_web/downloads/codelist_SMHI.xlsx",
  sheet = 1,
  skip = 1,
  force = FALSE,
  clean_cache_days = 30
)

Value

A tibble containing the contents of the requested sheet.

Arguments

url

Character string with the URL to the SHARK codes Excel file. Defaults to the official SMHI codelist.

sheet

Sheet to read. Can be either the sheet name or its index (default is 1).

skip

Number of rows to skip before reading data (default is 1, to skip the header row).

force

Logical; if TRUE, forces re-download of the Excel file even if a cached copy is available. Default is FALSE.

clean_cache_days

Numeric; if not NULL, cached SHARK code Excel files older than this number of days will be automatically deleted. Defaults to 30. Set to NULL to disable automatic cleanup.

See Also

clean_shark4r_cache() to manually clear cached files.

Examples

Run this code
# \donttest{
  # Read the first sheet, skipping the first row
  codes <- get_shark_codes()
  head(codes)

  # Force re-download of the Excel file
  codes <- get_shark_codes(force = TRUE)
# }

Run the code above in your browser using DataLab