Skip to content

πŸ“Š R for Accessing ERDDAP Data

The rerddap package provides an easy way to query ERDDAP servers directly from R.
It supports searching, filtering, and downloading datasets in both tabledap and griddap formats.

πŸ“– Full documentation: rerddap on CRAN


βš™οΈ Setting Up the Environment

To access CanWIN’s ERDDAP server:

library(rerddap) # load package

# Point to CanWIN's ERDDAP server
Sys.setenv(RERDDAP_DEFAULT_URL = "https://canwinerddap.ad.umanitoba.ca/erddap")

servers()   # list available ERDDAP servers
eurl()      # print the current server URL
ed_datasets() # list all datasets on the server

Tip

By default, rerddap connects to NOAA’s ERDDAP server.
Use Sys.setenv(RERDDAP_DEFAULT_URL = "https://canwinerddap.ad.umanitoba.ca/erddap") to switch to CanWIN’s server.

πŸ” Searching and Filtering Datasets

You can search datasets by keywords, variables, or type:

# Search ERDDAP with specific parameters
ed_search(query = "temperature", which = "tabledap", url = eurl())

# Another example
ed_search(query = "bathymetry", which = "tabledap")

πŸ“– More advanced search options: rerddap search documentation

πŸ†” Finding Dataset IDs

To retrieve data, you need the Dataset ID. Find IDs on the CanWIN ERDDAP dataset listing (last column).

dat <- ed_datasets()
IDs <- dat$Dataset.ID
print(IDs) # view all dataset IDs

πŸ“₯ Importing a Dataset into RStudio

Example using the GreenEdge Nutrient dataset:

green <- "GreenEdge_Nutrient_3e39_afd6_0a1e"

# Get dataset info
info(green)

# Open in browser
browse(green)

# Load into R
nutrient <- tabledap(green)

# For grid datasets
griddap("<replace with datasetID>")

Note

Use tabledap() for tabular datasets and griddap() for gridded datasets.

Tip

You can also use if (interactive()) with functions like browse() and info()
to explore datasets in your browser before downloading.

πŸ’Ύ Downloading Data

You can save datasets directly to disk or keep them in memory:

# Save to disk
disk(path = "D:/R/Ckan", overwrite = TRUE)

# Save to memory (data frame in RStudio)
memory()

Example for tabledap:

tabledap(
  green,
  fields = c("latitude", "longitude", "sample_date"),
  url = eurl(),
  store = disk(path = "D:/R/Ckan", overwrite = TRUE)
)

Example for griddap:

griddap(
  "<replace with datasetID>",
  fields = "all",
  stride = 1,
  fmt = "nc",
  url = eurl(),
  store = disk(path = "D:/R/Ckan", overwrite = TRUE),
  read = TRUE
)

πŸš€ Quick Start Workflow

  1. πŸ”— Set server β†’ Sys.setenv(RERDDAP_DEFAULT_URL = "...")
  2. πŸ” Search datasets β†’ ed_search() or ed_datasets()
  3. πŸ†” Get dataset ID β†’ from listing or dat$Dataset.ID
  4. πŸ“₯ Retrieve data β†’ tabledap() or griddap()
  5. πŸ’Ύ Save results β†’ disk() or memory()