get_shark_data | R Documentation |
The get_shark_data
function retrieves data from the SHARK database hosted by SMHI. The function sends a POST request
to the SHARK API with customizable filters, including year, month, taxon name, water category, and more, and returns the
retrieved data as a structured data.frame
. To view available filter options, see get_shark_options
.
get_shark_data(
tableView = "sharkweb_overview",
headerLang = "internal_key",
save_data = FALSE,
file_path = NULL,
delimiters = "point-tab",
lineEnd = "win",
encoding = "utf_8",
dataTypes = c(),
bounds = c(),
fromYear = NULL,
toYear = NULL,
months = c(),
parameters = c(),
checkStatus = "",
qualityFlags = c(),
deliverers = c(),
orderers = c(),
projects = c(),
datasets = c(),
minSamplingDepth = "",
maxSamplingDepth = "",
redListedCategory = c(),
taxonName = c(),
stationName = c(),
vattenDistrikt = c(),
seaBasins = c(),
counties = c(),
municipalities = c(),
waterCategories = c(),
typOmraden = c(),
helcomOspar = c(),
seaAreas = c(),
hideEmptyColumns = FALSE,
row_limit = 10^7,
prod = TRUE,
verbose = TRUE
)
tableView |
Character. Specifies the columns of the table to retrieve. Options include:
Default is |
headerLang |
Character. Language option for column headers. Possible values:
|
save_data |
Logical. If TRUE, the data will be saved to a specified file (see |
file_path |
Character. The file path where the data should be saved. Required if |
delimiters |
Character. Specifies the delimiter used to separate values in the file, if |
lineEnd |
Character. Defines the type of line endings in the file, if |
encoding |
Character. Sets the file's text encoding, if |
dataTypes |
Character vector. Specifies data types to filter. Possible values include:
|
bounds |
A numeric vector of length 4 specifying the geographical search boundaries in decimal degrees,
formatted as |
fromYear |
Integer (optional). The starting year for data retrieval.
If set to |
toYear |
Integer (optional). The ending year for data retrieval.
If set to |
months |
Integer vector. The months to retrieve data for, e.g., |
parameters |
Character vector. Optional parameters to filter the results by, such as |
checkStatus |
Character string. Optional status check to filter results. |
qualityFlags |
Character vector. Specifies the quality flags to filter the data. By default, all data are included, including those with the "B" flag (Bad). |
deliverers |
Character vector. Specifies the data deliverers to filter by. |
orderers |
Character vector. Orderers to filter by specific organizations or individuals. |
projects |
Character vector. Projects to filter data by specific research or monitoring projects. |
datasets |
Character vector. Datasets to filter data by specific datasets. |
minSamplingDepth |
Numeric. Minimum sampling depth (in meters) to filter the data. |
maxSamplingDepth |
Numeric. Maximum sampling depth (in meters) to filter the data. |
redListedCategory |
Character vector. Red-listed taxa for conservation filtering. |
taxonName |
Character vector. Optional vector of taxa names to filter by. |
stationName |
Character vector. Station names to filter data by specific stations. |
vattenDistrikt |
Character vector. Water district names to filter by Swedish water districts. |
seaBasins |
Character vector. Sea basins to filter by. |
counties |
Character vector. Counties to filter by specific administrative regions. |
municipalities |
Character vector. Municipalities to filter by. |
waterCategories |
Character vector. Water categories to filter by. |
typOmraden |
Character vector. Type areas to filter by. |
helcomOspar |
Character vector. HELCOM or OSPAR areas for regional filtering. |
seaAreas |
Character vector. Sea area codes to filter by specific sea areas. |
hideEmptyColumns |
Logical. Whether to hide empty columns. Default is FALSE. |
row_limit |
Numeric. Specifies the maximum number of rows that can be retrieved in a single request. If the requested data exceeds this limit, the function automatically downloads the data in yearly chunks. The default value is 10 million rows. |
prod |
Logical. Whether to query the PROD (production) server or the SMHI internal TEST (testing) server. Default is TRUE (PROD). |
verbose |
Logical. Whether to display progress information. Default is TRUE. |
This function sends a POST request to the SHARK API with the specified filters. The response is parsed as JSON
and then converted into a data.frame
. The function handles the dynamic construction of the query body to filter
the data based on the provided parameters. If the row_limit
parameter is reached, the data retrieval process is
split into manageable chunks to avoid overwhelming the API or running into memory issues. Please note that making very
large requests, such as retrieving the entire database, can be extremely memory-intensive.
A data.frame
containing the retrieved SHARK data, with column names based on the API's response.
get_shark_options
get_shark_table_counts
## Not run:
# Retrieve chlorophyll data from 2019 to 2020 for April to June
shark_data <- get_shark_data(fromYear = 2019, toYear = 2020,
months = c(4, 5, 6), dataTypes = c("Chlorophyll"))
View(shark_data)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.