rnoaa (version 0.2.0)

erddap_data: Get ERDDAP data.

Description

Get ERDDAP data.

Usage

erddap_data(datasetid, ..., fields = NULL, distinct = FALSE,
  orderby = NULL, orderbymax = NULL, orderbymin = NULL,
  orderbyminmax = NULL, units = NULL, callopts = list())

Arguments

datasetid
Dataset id
...
Any number of key-value pairs in quotes as query constraints. See Details & examples
fields
Columns to return, as a character vector
distinct
If TRUE ERDDAP will sort all of the rows in the results table (starting with the first requested variable, then using the second requested variable if the first variable has a tie, ...), then remove all non-unique rows of data. In many situations, ERDDAP can return distinct values quickly and efficiently. But in some cases, ERDDAP must look through all rows of the source dataset.
orderby
If used, ERDDAP will sort all of the rows in the results table (starting with the first variable, then using the second variable if the first variable has a tie, ...). Normally, the rows of data in the response table are in the order they arrived from the data source. orderBy allows you to request that the results table be sorted in a specific way. For example, use orderby=c("stationID,time") to get the results sorted by stationID, then time. The orderby variables MUST be included in the list of requested variables in the fields parameter.
orderbymax
Give a vector of one or more fields, that must be included in the fields parameter as well. Gives back data given constraints. ERDDAP will sort all of the rows in the results table (starting with the first variable, then using the second variable if the first variable has a tie, ...) and then just keeps the rows where the value of the last sort variable is highest (for each combination of other values).
orderbymin
Same as orderbymax parameter, except returns minimum value.
orderbyminmax
Same as orderbymax parameter, except returns two rows for every combination of the n-1 variables: one row with the minimum value, and one row with the maximum value.
units
One of 'udunits' (units will be described via the UDUNITS standard (e.g.,degrees_C)) or 'ucum' (units will be described via the UCUM standard (e.g., Cel)).
callopts
Further args passed on to httr::GET (must be a named parameter)

Details

For key-value pair query constraints, the valid operators are =, != (not equals), =~ (a regular expression test), <, <=, >, and >= . For regular expressions you need to add a regular expression. For others, nothing more is needed. Construct the entry like 'time>=2001-07-07' with the parameter on the left, value on the right, and the operator in the middle, all within a set of quotes. Since ERDDAP accepts values other than =, we can't simply do time = '2001-07-07' as we normally would. Server-side functionality: Some tasks are done server side. You don't have to worry about what that means. They are provided via parameters in this function. See distinct, orderby, orderbymax, orderbymin, orderbyminmax, and units.

Examples

Run this code
## Not run: ------------------------------------
# # Just passing the datasetid without fields gives all columns back
# out <- erddap_data(datasetid='erdCalCOFIfshsiz')
# nrow(out)
# 
# # Pass time constraints
# head(erddap_data(datasetid='erdCalCOFIfshsiz', 'time>=2001-07-07', 'time<=2001-07-08'))
# 
# # Pass in fields (i.e., columns to retrieve) & time constraints
# erddap_data(datasetid='erdCalCOFIfshsiz',fields=c('longitude','latitude','fish_size','itis_tsn'),
#    'time>=2001-07-07','time<=2001-07-10')
# erddap_data(datasetid='erdCinpKfmBT', fields=c('latitude','longitude',
#    'Aplysia_californica_Mean_Density','Muricea_californica_Mean_Density'),
#    'time>=2007-06-24','time<=2007-07-01')
# 
# # Get info on a datasetid, then get data given information learned
# erddap_info('erdCalCOFIlrvsiz')$variables
# erddap_data(datasetid='erdCalCOFIlrvsiz', fields=c('latitude','longitude','larvae_size',
#    'itis_tsn'), 'time>=2011-10-25', 'time<=2011-10-31')
# 
# # An example workflow
# ## Search for data
# (out <- erddap_search(query='fish size'))
# ## Using a datasetid, search for information on a datasetid
# id <- out$info$dataset_id[1]
# erddap_info(datasetid=id)$variables
# ## Get data from the dataset
# head(erddap_data(datasetid = id, fields = c('latitude','longitude','scientific_name')))
# 
# # Time constraint
# ## Limit by time with date only
# erddap_data(datasetid = id, fields = c('latitude','longitude','scientific_name'),
#    'time>=2001-07-14')
# ## Limit by time with hours and date
# erddap_data(datasetid='ndbcSosWTemp', fields=c('latitude','longitude','sea_water_temperature'),
#    'time>=2014-05-14T15:15:00Z')
# 
# # Use distinct parameter
# erddap_data(datasetid='erdCalCOFIfshsiz',fields=c('longitude','latitude','fish_size','itis_tsn'),
#    'time>=2001-07-07','time<=2001-07-10', distinct=TRUE)
# 
# # Use units parameter
# ## In this example, values are the same, but sometimes they can be different given the units
# ## value passed
# erddap_data(datasetid='erdCinpKfmT', fields=c('longitude','latitude','time','temperature'),
#    'time>=2007-09-19', 'time<=2007-09-21', units='udunits')
# erddap_data(datasetid='erdCinpKfmT', fields=c('longitude','latitude','time','temperature'),
#    'time>=2007-09-19', 'time<=2007-09-21', units='ucum')
# 
# # Use orderby parameter
# erddap_data(datasetid='erdCinpKfmT', fields=c('longitude','latitude','time','temperature'),
#    'time>=2007-09-19', 'time<=2007-09-21', orderby='temperature')
# # Use orderbymax parameter
# erddap_data(datasetid='erdCinpKfmT', fields=c('longitude','latitude','time','temperature'),
#    'time>=2007-09-19', 'time<=2007-09-21', orderbymax='temperature')
# # Use orderbymin parameter
# erddap_data(datasetid='erdCinpKfmT', fields=c('longitude','latitude','time','temperature'),
#    'time>=2007-09-19', 'time<=2007-09-21', orderbymin='temperature')
# # Use orderbyminmax parameter
# erddap_data(datasetid='erdCinpKfmT', fields=c('longitude','latitude','time','temperature'),
#    'time>=2007-09-19', 'time<=2007-09-21', orderbyminmax='temperature')
# # Use orderbymin parameter with multiple values
# erddap_data(datasetid='erdCinpKfmT',fields=c('longitude','latitude','time','depth','temperature'),
#    'time>=2007-06-10', 'time<=2007-09-21', orderbymax=c('depth','temperature'))
# 
# # Spatial delimitation
# erddap_data(datasetid = 'erdCalCOFIfshsiz', fields = c('latitude','longitude','scientific_name'),
#  'latitude>=34.8', 'latitude<=35', 'longitude>=-125', 'longitude<=-124')
# 
# # Integrate with taxize
# out <- erddap_data(datasetid = 'erdCalCOFIfshsiz',
#    fields = c('latitude','longitude','scientific_name','itis_tsn'))
# tsns <- unique(out$itis_tsn[1:100])
# library("taxize")
# classif <- classification(tsns, db = "itis")
# head(rbind(classif)); tail(rbind(classif))
## ---------------------------------------------

Run the code above in your browser using DataLab