WriteXobs {HYPEtools} | R Documentation |
Write an 'Xobs.txt' File
Description
WriteXobs
writes or appends an observation data set to an Xobs file.
Usage
WriteXobs(
x,
filename,
append = FALSE,
comment = NULL,
variable = NULL,
subid = NULL,
last.date = NULL,
timestep = "d"
)
Arguments
x |
A data frame, e.g. an object originally imported with |
filename |
A character string naming a file to write to. Windows users: Note that Paths are separated by '/', not '\'. |
append |
Logical. If |
comment |
A character string to be exported as first row comment in the Xobs file. If provided, it takes precedence over
a |
variable |
A character vector to be exported as second row in the Xobs file. Must contain the same number of
variables as |
subid |
Third row in Xobs, containing SUBIDs (integer). Behavior otherwise as argument |
last.date |
Optional date-time of last observation in existing Xobs file as text string. Only relevant with |
timestep |
Character string, either "day" or "hour", giving the time step between observations. Can be abbreviated. |
Details
WriteXobs
writes a 'Xobs.txt' file, typically originating from an imported and modified 'Xobs.txt'.
HYPE Xobs files contain a three-row header, with a comment line first, next a line of variables, and then a line of subids.
Objects imported with ReadXobs
include attributes holding this information, and WriteXobs
will use this
information. Otherwise, these attributes can be added to objects prior to calling WriteXobs
, or passed as function
arguments.
If argument append
is TRUE
, the function requires daily or hourly time steps as input.
The date-time column must be of class POSIXct
, see as.POSIXct
. Objects returned from
ReadXobs
per default have the correct class for the date-time column. When appending to existing file, the
function adds new rows with '-9999' values in all data columns to fill any time gaps between existing and new data. If time
periods overlap, the export will stop with an error message. Argument last.date
can be provided to speed up appending exports,
but per default, WriteXobs
extracts the last observation in the existing file automatically.
Value
No return value, called for export to text files.
Note
Both variable
and subid
do not include elements for the first column in the Xobs file/object, in accordance
with ReadXobs
. These elements will be added by the function.
Examples
te <- ReadXobs(filename = system.file("demo_model", "Xobs.txt", package = "HYPEtools"))
WriteXobs(x = te, filename = tempfile())