Skip to contents

Reads the output.rch file generated by SWAT, allowing users to filter the data by variables, reach IDs, and time steps (daily or monthly).

Usage

output_rch(
  file = "output.rch",
  variable = NULL,
  target_id = NULL,
  time_step = "daily",
  output_start_date
)

Arguments

file

Character. Absolute path to the output.rch file. Default is "output.rch".

variable

Character vector with the names of variables to read. Use get_swat_vars("rch") to list all options. If NULL, all variables are read.

target_id

Numeric vector of reach IDs to extract. Default NULL retrieves all reaches.

time_step

Character. Time step of the simulation ("daily" or "monthly"). Default is "daily".

output_start_date

Character. Date when SWAT output generation begins (first day after warm-up), in "yyyy-mm-dd" format.

Value

A data.frame with the selected variables for each reach and time step. Columns "RCH" (reach ID) and "MON" (Date) are always included.

See also

Other Output readers: get_swat_vars(), output_hru(), output_sub(), read_pcp(), read_tmp()

Examples

# Example with package data
tmpdir <- tempdir()
get_swat_example(tmpdir)
rch_file <- file.path(tmpdir, "TxtInOut", "output.rch")
rch_data <- output_rch(file = rch_file, variable = c("FLOW_OUTcms"),
                       target_id = NULL, time_step = "daily",
                       output_start_date = "2011-01-01")
head(rch_data)

if (FALSE) { # \dontrun{
# Example with external SWAT project
rch_data <- output_rch(file = "C:/SWAT_Project/TxtInOut/output.rch",
                       variable = c("FLOW_OUTcms"), target_id = 5,
                       time_step = "monthly",
                       output_start_date = "2000-01-01")
} # }