read_ts_tables {tsdb}R Documentation

Read Time-Series Data from Files

Description

Read time-series data from files and merge them.

Usage

read_ts_tables(file, dir, t.type = "guess",
               start, end, columns,
               return.class = NULL,
               drop.weekends = FALSE,
               column.names = "%dir%/%file%::%column%",
               backend = "csv",
               read.fn = NULL,
               frequency = "1 sec",
               timestamp)

Arguments

file

character

dir

character

t.type

character: guess, Date or POSIXct

start

a timestamp: either of classes Date or POSIXct (possibly including timezone information), or a character string. Strings are passed to as.Date/as.POSIXct. Note in particular that a string of the form "YYYY-MM-DD HH:MM:SS", when passed to as.POSIXct, will be interpreted as a datetime in the current timezone.

It is best to always specify start: if start is missing, the function will use the first timestamp of the first time-series it reads.

end

a timestamp: either of classes Date or POSIXct (possibly including timezone information), or a character string. Strings are passed to as.Date/as.POSIXct. Note in particular that a string of the form "YYYY-MM-DD HH:MM:SS", when passed to as.POSIXct, will be interpreted as a datetime in the current timezone.

It is best to always specify end: if end is missing, the function will use the current time (which may not be appropriate: for instance, when forecasts are stored).

columns

character.

return.class

NULL (default) or character: if NULL, a list is returned. Also supported are zoo, data.frame and ts_table.

drop.weekends

logical

column.names

character: a format string for column names; may contain %dir%, %file%, and %column%. It is only used when return.class is data.frame or zoo.

backend

character: currently, only ‘csv’ is fully supported

read.fn

NULL or character: use ‘fread’ to use fread from package data.table

frequency

character; used compute a regular grid between start and end. The argument is only used when t.type is POSIXct (or guessed to be POSIXct) and no timestamp is specified. If set to NA, the function will first read all files and compute timestamp as the union of all files' timestamps.

timestamp

a vector of timestamps: if specified, only data at the times in timestamp are selected

Details

Read time-series data from CSV files.

Value

When return.class is NULL, a list:

data

a numeric matrix

timestamp

Date or POSIXct

columns

character

file.path

character

Otherwise an object of class as specified by argument return.class.

Author(s)

Enrico Schumann

See Also

write_ts_table

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%")

[Package tsdb version 1.1-0 Index]