write_ts_table: Write Time-Series Data to File

View source: R/functions.R

write_ts_tableR Documentation

Write Time-Series Data to File

Description

Write time-series data to files.

Usage

write_ts_table(ts, dir, file, add = FALSE, overwrite = FALSE,
               replace.file = FALSE, backend = "csv")

Arguments

ts

a ts_table

dir

character

file

character

add

logical: if TRUE, add data with timestamps that are not in a file.

overwrite

logical: overwrite existing file when data differs. overwrite implies add.

replace.file

logical: if TRUE, an existing file is deleted and replaced by a new file (i.e. containing ts)

backend

a string; currently, only csv is supported

Details

The function takes a ts_table and writes it to a file.

If the file already exists and both add and overwrite are FALSE (the default), nothing is written.

When add is TRUE, the function checks if ts contains timestamps not yet in the file and, if there are any, writes only those data.

When overwrite is TRUE, the function merges all observations in the file with those in ts and writes the result back to the file. If ts contains timestamps that were already in the file, the data in the file are overwritten. Note that no data will be removed from the file: timestamps not in ts remain unchanged in the file.

Value

Invisibly, the number of data rows written to a file.

Author(s)

Enrico Schumann

See Also

read_ts_tables

Examples

t1 <- ts_table(1:3, as.Date("2018-12-3") + 1:3, columns = "A")
t2 <- ts_table(4:5, as.Date("2018-12-3") + 1:2, columns = "A")

d <- tempdir()  ## this is just an example.
                ## Actual (valuable) data should never
                ## be stored in a tempdir!

write_ts_table(t1, dir = d, file = "t1")
write_ts_table(t2, dir = d, file = "t2")

read_ts_tables(c("t1", "t2"),
               dir = d, columns = "A",
               return.class = "zoo",
               column.names = "%file%.%column%")

tsdb documentation built on March 7, 2023, 7:31 p.m.

Related to write_ts_table in tsdb...