query: Query NAMC database.

View source: R/queries.R

queryR Documentation

Query NAMC database.

Description

query retrieves data from NAMC given a specified API endpoint name.

Usage

query(
  api_endpoint,
  args = list(),
  include = c(),
  exclude = c(),
  filter = list(),
  sort = c(),
  limit = NA,
  api = .pkgenv$api,
  expand_metadata = TRUE,
  default_JSON_fieldName = .pkgenv$data$default_JSON_fieldName,
  ...
)

Arguments

api_endpoint

string A NAMC API endpoint name. Available endpoints can be found via the endpoints() function.

args

a list of named arguments to pass to the API endpoint. Can also be passed individually in ...

include

is a vector of fields to include from the endpoint.

exclude

is a vector of fields to exclude from the endpoint.

filter

list A list containing filter parameters.

sort

list A list containing fields / directions to sort by.

limit

numeric The number of results desired.

api

namc_api An instance of the namc_api class having a default of a pre-initialized package object

expand_metadata

logical if JSON metadata field is expanded into dataframe columns

default_JSON_fieldName

"metadata" is the preset default

...

named arguments to merge with args and pass to the API endpoint.

Details

Providing a desired endpoint and filtering the function retrieves data from the NAMC database. If not already authenticated the will trigger the authentication / account creation routines. By default all fields are included. Use include and exclude arguments to limit returned fields.

Value

data.frame A dataframe containing the query results.

See Also

info(),browseVignettes("NAMC-API-Overview")

Other query functions: raw_query(), save()

Examples


sites = NAMCr::query(
  api_endpoint = 'sites',
  include = c('station','lat','long')),
  filter = list(
    station = c('station1','station2'),
    lat = list(
      data = c(42,46),
      type = 'between'
    )
  )
  sort = c('station','lat'),
  limit = 50
)

# View full API docs in console
NAMCr::info()


namc-utah/NAMCr documentation built on Feb. 12, 2024, 4:29 a.m.