π 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).
π₯ 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
- π Set server β
Sys.setenv(RERDDAP_DEFAULT_URL = "...") - π Search datasets β
ed_search()ored_datasets() - π Get dataset ID β from listing or
dat$Dataset.ID - π₯ Retrieve data β
tabledap()orgriddap() - πΎ Save results β
disk()ormemory()