TSdbiMethods: TSdbi methods to importing time series from web sources via...

Description Usage Arguments Details Value See Also Examples

Description

Get time series data from web data sources, importing them using Javascript object notation. Direct connections or a proxy connection are possible. (Only Statistics Canada connections are currently supported.)

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
    json() 
    ## S4 method for signature 'jsonConnection,missing'
TSconnect(
	q, dbname, user=NULL, password = NULL, host=NULL, ...)
    ## S4 method for signature 'character,TSjsonConnection'
TSget(
	serIDs, con=getOption("TSconnection"), 
	TSrepresentation=getOption("TSrepresentation"), 
	tf = NULL, start = tfstart(tf), end = tfend(tf), names=serIDs, 
        TSdescription=FALSE, TSdoc=FALSE, TSlabel=FALSE, TSsource=TRUE,
	quiet = TRUE, repeat.try=3, ...)
    ## S4 method for signature 'character,TSjsonConnection'
TSdates(
	serIDs, con, vintage=NULL, panel=NULL, ... )  
    ## S4 method for signature 'character,TSjsonConnection'
TSdescription(x, con, ... )  
    ## S4 method for signature 'character,TSjsonConnection'
TSdoc(x, con, ... )  
    ## S4 method for signature 'character,TSjsonConnection'
TSlabel(x, con, ... )  
    ## S4 method for signature 'character,TSjsonConnection'
TSsource(x, con, ... )  

Arguments

q

A character string indicating the query interface to use, or a database connection object.

dbname

The name of the database to which the connection should be established, omitted if q is a database connection object.

con

a database connection object.

serIDs

identifiers for series on the database.

vintage

character string indicating vintage of the series on the database (not supported by this database).

panel

character string indicating panel of the series on the database (not supported by this database).

x

time series data(TSput), or identifiers for series on the database (TSdoc and TSdescription).

names

optional character vector to use for series names in the R object.

tf

time frame for trimming data, passed to tfwindow.

start

time frame for trimming data, passed to tfwindow.

end

time frame for trimming data, passed to tfwindow.

TSrepresentation

time representation for returned series. (See TSget in package TSdbi.)

TSdescription

logical to indicate if description shouod be retrieved.

TSdoc

logical to indicate if documentation shouod be retrieved.

TSlabel

logical to indicate if label shouod be retrieved.

TSsource

logical to indicate if source information shouod be retrieved.

quiet

logical to suppress progress report.

repeat.try

integer number of times to attempt retrieval before giving up.

user

(unused) a character string indicating a user id.

password

(unused) a character string indicating a password.

host

(unused) a character string indicating a host computer.

...

Arguments passed to jsonCall.

Details

These functions interface to web time series databases and import data using simple JavaScript Object Notation (JSON). The web source can be a proxy portal to the real database, simply providing an intermediate server that contacts the real server. The proxy retrieves and relays the data. This can be convenient in some cases, for example, when all the necessary Python cannot be installed on the client machine.

The function TSconnect establishes the source of the web data, and whether a proxy server will be used or not. Argument dbname specifies a recognized database (e.g "cansim") which is expanded to an appropriate string to find the database.

If a proxy server is to be used, the dbname should specify the proxy server, for example, dbname="proxy-cansim". In this case credentials will be needed. The user, password, and host, can be specified as arguments. If specified as NULL (the default) then they will be determined by reading a file ~/.TSjson.cfg which should have a line with four fields:

[proxy-cansim] user password host

The first field should match the dbname specification. Currently only a single line is supported, starting with "[proxy-cansim]", but the format is intended for extension to support proxies to different web databases.

If the file does not exist then environment variables "TSJSONUSER", "TSJSONPASSWORD", and "TSJSONHOST" will be used.

For unrecognized databases specified in dbname, the value of dbname is simply appended to the URL specification, allowing for an arbitrary database host. (But the value returned by the host must be a time series in the recognized format in order for this to work. The URL specification is expanded using other arguments to "http://user:password@host/dbname/serID".

TSget calls Python code to extract the data. The Python code returns a simple JSON format which is decoded by fromJSON. The TSget function argument serId specifies the series to return.

TSjson does not support writing data to the source.

The classes jsonDriver and TSjsonConnection extend classes DBIDriver and DBIConnection in the DBI package.

See the vignette for package TSdata for additional examples.

Value

Depends.

See Also

TSdates, TSget, tfwindow,

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
  require("TSjson")
  require("findpython")
## Not run: 
  if(can_find_python_cmd(
         minimum_version="2.6",
         maximum_version="2.9",
         required_modules=c("sys", "re", "urllib2", "csv", "mechanize", "json"),
         silent=TRUE)){

    con <- TSconnect("json", dbname="cansim")

    TSdates(c("v498086", "v498087","V122746", "v687341", "V36610", "v141"), con)
 
    TSdescription(c("v687341", "v687342"), con)

    x <- TSget("v498086", con)
    require("tfplot")
    tfplot(x)
    }
 
## End(Not run)

TSjson documentation built on May 2, 2019, 4:50 p.m.

Related to TSdbiMethods in TSjson...