Package 'tceqcrp'

Title: Scripted Downloads from the TCEQ CRP Water Quality Portal
Description: Programmatic access to the Texas Commission on Environmental Quality (TCEQ) Clean Rivers Program (CRP) public data portal. Handles JSF session state, basin/station selection, and download of tab-delimited water quality data files.
Authors: Michael Schramm [aut, cre]
Maintainer: Michael Schramm <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-10-10 14:12:18 UTC
Source: https://github.com/mps9506/tceqcrp

Help Index


CRP river basin codes

Description

CRP river basin codes

Usage

crp_basins()

Value

A tibble mapping basin numbers to basin names.


CRP data type codes

Description

CRP data type codes

Usage

crp_data_types()

Value

A tibble mapping menu values to data type labels.


Download CRP water quality data

Description

Download CRP water quality data

Usage

crp_download(
  form,
  startdate,
  enddate,
  data_type,
  basin,
  format = "14",
  segment_rows,
  param_code = "",
  path = tempfile(fileext = ".txt"),
  quiet = FALSE
)

Arguments

form

A crp_form from crp_select_basin() (must be the basin-selected form, which carries the correct ViewState).

startdate, enddate

Date strings in "MM/DD/YYYY" format.

data_type

Data type code. See crp_data_types().

basin

Basin number. See crp_basins().

format

Output format code (default "14", combined). See crp_formats().

segment_rows

Integer vector of table rows. See crp_rows_for_segments().

param_code

Optional parameter code filter.

path

File path to write the downloaded data to.

quiet

Suppress progress messages.

Value

Invisibly, a list with path, post_resp, and stream_resp.

Examples

## Not run: 
form  <- crp_get_form()
form2 <- crp_select_basin(form, 12)
st    <- crp_stations(form2)
rows  <- crp_rows_for_ids(st, c("1201", "1202"))
crp_download(form2, "01/01/2020", "12/31/2020",
             data_type = 1, basin = 12, station_rows = rows,
             path = "brazos.txt")

## End(Not run)

CRP output format codes

Description

CRP output format codes

Usage

crp_formats()

Value

A tibble mapping menu values to output-format labels.


Start a CRP session

Description

Fetches the CRP query page, establishes a session, and captures the JSF ViewState token needed for subsequent requests.

Usage

crp_get_form()

Value

An object of class crp_form.

Examples

## Not run: 
form <- crp_get_form()

## End(Not run)

List segments available in a basin

Description

List segments available in a basin

Usage

crp_list_segments(basin)

Arguments

basin

Basin number (1-25). See crp_basins().

Value

A tibble with row, segment_id, segment_desc.


Download CRP data in a single call

Description

Download CRP data in a single call

Usage

crp_query(
  basin,
  startdate,
  enddate,
  data_type,
  segment_ids,
  format = "14",
  param_code = "",
  path = tempfile(fileext = ".txt"),
  read = TRUE,
  clean_names = FALSE,
  quiet = FALSE
)

Arguments

basin

Basin number (1-25). See crp_basins().

startdate, enddate

Date strings "MM/DD/YYYY".

data_type

Data type code. See crp_data_types().

segment_ids

Character vector of segment IDs.

format

Output format code (default combined).

param_code

Optional parameter code filter.

path

File path to write to.

read

If TRUE (default), return the parsed tibble; otherwise the file path.

clean_names

If TRUE, convert column names to snake_case (requires the janitor package). Ignored when read = FALSE.

quiet

Suppress messages.

Value

A tibble (if read = TRUE) or the file path (invisibly).

Examples

## Not run: 
brazos <- crp_query(
  basin       = 12,
  startdate   = "01/01/2020",
  enddate     = "12/31/2020",
  data_type   = 1,
  segment_ids = "1202",
  clean_names = TRUE
)

## End(Not run)

Read a downloaded CRP data file

Description

Read a downloaded CRP data file

Usage

crp_read(path, clean_names = FALSE, ...)

Arguments

path

Path to a file written by crp_download().

clean_names

If TRUE, convert column names to snake_case (requires the janitor package).

...

Passed on to readr::read_delim().

Value

A tibble.


Find segment table rows by segment ID

Description

Find segment table rows by segment ID

Usage

crp_rows_for_segments(segments, ids)

Arguments

segments

A tibble from crp_segments().

ids

Character vector of segment IDs (e.g. c("1202", "1202A")).

Value

Integer vector of row values for crp_download().


Extract the segment table for the selected basin

Description

Extract the segment table for the selected basin

Usage

crp_segments(form)

Arguments

form

A crp_form from crp_select_basin().

Value

A tibble with columns row, segment_id, segment_desc.


Select a river basin and retrieve its segment list

Description

Select a river basin and retrieve its segment list

Usage

crp_select_basin(form, basin)

Arguments

form

A crp_form from crp_get_form().

basin

Basin number (1-25). See crp_basins().

Value

A new crp_form with the segment table populated and a fresh ViewState. Pass this to crp_segments() and crp_download().