This is the base function for queries for most of the CAX tables. Default queries will download 1000 records. You will want to make a filtered query by passing in flist as a list with the column name values to filter on.

rcax_table_query(
  tablename = NULL,
  flist = NULL,
  qlist = NULL,
  cols = NULL,
  sortcols = NULL,
  type = c("data.frame", "colnames"),
  GETargs = list(table_id = NULL, recordloc = "records", key = NULL, parse = TRUE),
  ...
)

Arguments

tablename

The name of the table in the CAX API. See rcax_datasets() for the names.

flist

A filter for the query. See details and rcax_filter()

qlist

Additional query parameters. See rcax_table_query() for details.

cols

column names to return. Use cols=NULL if you want all columns. Names are case insensitive.

sortcols

The columns to sort on for the returned table. The order of sortcols indicates the order of sorting. Start with the smallest group and work outwards, e.g. c("spawningyear", "popid", "MPG"). Names are case insensitive.

type

whether to return the table ("data.frame") or colnames with definitions ("colnames"). Default is to return the table as a data frame.

GETargs

A list of arguments for the rcax_GET() call. These do not need to be specified by the user unless the user wants to change the default values. table_id This is the CAX table id. It is looked up using tablename and rCAX:::caxpops (an internal dataset). If table_id is passed in via GETargs, it will override the default table id lookup. recordloc This is the name of the record we want in the list returned from the GET call. key is the API key.

...

Curl options passed to HttpClient

Value

data frame if type="data.frame" (default) and the colnames if type="colnames"

Details

The required query parameters are table_id and XAPIKEY. These are set from the information in GETargs. table_id is normally looked up from rcax_datasets() using the tablename. The qlist argument is any additional query parameters. The following are some of the available extra (meaning not required) query parameters.

  • page=num Integer of the page selected.

  • per_page=num Integer for the number of records per page.

  • limit=num Maximum number of records to return. Default is 1000.

  • agency=character Agency that submitted the record. You can designate one or more (comma-separated) agency acronyms: IDFG, WDFW, ODFW, CRITFC, CCT, NOAA.

  • updated_since Date since epoch in seconds: 2012-04-24 15:05:22 -0400 = 1335294322.

  • popid Population id in NOSA tables.

Filtering, i.e. subsetting, the query is specified using the flist argument. This is a list with the column name and value. See rcax_filter() for the filtering code which writes the filter query parameter that is added to the GET query. See rcax_filter() for examples of how one passes in flist.

Examples

a <- rcax_table_query(tablename="NOSA", qlist = list(limit=5))
a[, c("popid", "spawningyear", "nosaij", "nosaej")]
#>   popid spawningyear nosaij nosaej
#> 1    58         2001   8637       
#> 2   130         2010          1382
#> 3     7         2005     38     35
#> 4    13         1967   1778   1715
#> 5   164         1991          2233