Get Time Series Data Using a Database Connection

Share:

Description

Get time series matrix structure from a database

Usage

1
2
3
4
5
    TSget(serIDs, con=getOption("TSconnection"),  ...)
    ## S4 method for signature 'character,missing'
TSget(serIDs, con=getOption("TSconnection"),  ...)
    ## S4 method for signature 'character,ANY'
TSget(serIDs, con=getOption("TSconnection"),  ...)

Arguments

con

A database connection.

serIDs

identifiers for series to extract.

...

Arguments passed to other methods. See details.

Details

These functions extract data from a database using a connection. This method is generic. The argument serIDs should give identifiers for the series to extract.

TSget and other functions also provide a way to query a regularly used database by setting the connection in options using options(TSconnection=con), so then only the series identifiers need to be specified in calls to TSget.

The user can specify a default time series representation with the argument TSrepresentation=something where something is "default" by default, but might be "zoo", "its", "timeSeries" or a function which is used to coerce the series to any representation. The TSrepresentation is passed in the ... argument. If TSrepresentation is a function it will be applied directly to the default returned by the query. The default is usually ts for monthly, quarterly, annual, and semi-annual data, and zoo otherwise, but the default may be different for some TSget methods. The conversion is done with the function tframePlus::changeTSrepresentation. The user should attach any package necessary for dealing with the representation.

If TSrepresentation is not specified, or is specified as "default", then for SQL packages (TSMySQL, TSPostgreSQL , TSSQLite, etc) the ts representation is used for data from tables "A", "Q", "M","S" and zoo otherwise. See TSput for a list of the various tables. For other packages the default is generally the same, or zoo for all series, but this may vary.

It would be possible to specify TSrepresentation="as.zoo", but this may result in as.zoo being applied twice, in which case some information about the time representation gets lost, so the best way to get a zoo represenation is to specify TSrepresentation="zoo".

Users can set a session default with options(TSrepresentation=something) so that this is always passed as an argument to TSget.

It is also possible to pass start, end, or tframe information to truncate the returned series. This is part of the ... argument passed to tfwindow. See tfwindow for more details. By default no truncation is applied.

If the database supports vintages or panels then it is also possible to set defaults for these with, for example, options(TSvintage="current") and options(TSpanel="Canada"). The default specification has to be supported by the database for this to work.

Also, if the database supports vintages or panels it is possible to give a vector value for one of vintage or panel as long as serIDs is length 1. (That is, only one of serIDs, vintage or panel can have more than one element.) In this case, if names is not specified, vintage or panel will be used for the series names in the returned time series matrix.

names, TSdescription, TSdoc andTSlabel can also be specified as arguments. (Passed in ...).

Value

A time series matrix.

See Also

TSdbi-package, TSconnect, TSput, TSdates tfwindow changeTSrepresentation