WriteObs {HYPEtools}R Documentation

Write 'Pobs.txt', 'Tobs.txt', 'Qobs.txt', and other observation data files

Description

Export forcing data and discharge observation files from R.

Usage

WriteObs(
  x,
  filename,
  dt.format = "%Y-%m-%d",
  round = NULL,
  signif = NULL,
  obsid = NULL,
  append = FALSE
)

WritePTQobs(
  x,
  filename,
  dt.format = "%Y-%m-%d",
  round = NULL,
  signif = NULL,
  obsid = NULL,
  append = FALSE
)

Arguments

x

The object to be written, a dataframe containing observation date-times in first and observations in SUBIDs or OBSIDs in remaining columns. If argument obsid is not provided, x must have an additional attribute obsid containing observation IDs/SUBIDs in column order.

filename

Path to and file name of the file to import. Windows users: Note that Paths are separated by '/', not '\'.

dt.format

Date-time format string as in strptime.

round, signif

Integer, number of decimal places and number of significant digits to export, respectively. See round and signif. Applied in sequence (round first and signif second). If NULL (default), the data to export is not touched.

obsid

Integer vector containing observation IDs/SUBIDs in same order as columns in x. To be exported as header in the obs file. Must contain the same number of IDs as observation series in x. If NULL, an attribute obsid in x is mandatory. An existing obsid argument takes precedence over a obsid attribute.

append

Logical, if TRUE, then table will be joined to the data in existing file and the output will be sorted by DATE (Rows will be added for any missing dates).

Details

WriteObs is a convenience wrapper function of fwrite to export a HYPE-compliant observation file. Headers are generated from attribute obsid on export (see attr on how to create and access it).

Observation IDs are SUBIDs or IDs connected to SUBIDs with a ForcKey.txt file.

If the first column in x contains dates of class POSIXt, then they will be formatted according to dt.format before writing the output file.

If round is specified, then WriteObs() will use round to round the observation values to a specified number of decimal places. Alternatively, signif can be used to round the observation values to a specified number of significant digits using signif. Finally, if both round and signif are specified, then the observation values will be first rounded to the number of decimal places specified with round and then rounded to the number of significant digits specified with signif.

Value

No return value, called for export to text files.

See Also

ReadObs WriteXobs

Examples

te <- ReadObs(filename = system.file("demo_model", "Tobs.txt", package = "HYPEtools"))
WriteObs(x = te, filename = tempfile())


[Package HYPEtools version 1.6.2 Index]