haver.dbcodes {Haver} | R Documentation

## Obtain List of Codes from a Haver Database

### Description

`haver.dbcodes` efficiently returns the full list of codes contained in a Haver database.

### Usage

    haver.dbcodes(database, format = "simple")

### Arguments

`database` | is a string. The database whose codes you want to retrieve.
`format` | is a string. One of ‘full’, ‘colon’, ‘:’, ‘at’, ‘@’, or ‘simple’, or any abbreviation thereof. ‘full’, ‘colon’, ‘:’ are synonyms and return the code list in database:seriescode format. ‘at’ and ‘@’ are synonyms and return the code list in seriescode@database format that is used in Excel. The default, ‘simple’, returns simple Haver codes.

### See Also

See Haver_package for all help entries related to the Haver package.

### Examples

    haver.path()
    haver.path("examples")

    ## 'haver.dbcodes' returns all codes in a database. The example database HAVERD
    ## only has three codes:
    print( ex_codes <- haver.dbcodes('haverd') )

    ## The fastest way to determine the size of a database is to check the 'length()'
    ## of this list.
    ## This is a lot faster than using 'haver.metadata' on an entire database
    ## and then checking the number of rows of the returned 'HaverMetaData' object.
    ## Compare:
    print( length(haver.dbcodes('havermqa')) )
    print( dim(haver.metadata(database='havermqa'))[1] )

    ## With large databases of 100,000+ codes, the speed differences are substantial,
    ## and particularly so when you work in DLX Direct mode (see ?Haver).

    ## Relatedly, you may be familiar with the technique of using 'haver.metadata'
    ## to query all data of a database:
    hmd <- haver.metadata(database='haverd')
    hd  <- haver.data(hmd)
    print( tail(hd) )

    ## You can achieve the exact same result using 'haver.dbcodes':
    ex_codes2 <- haver.dbcodes(database='haverd')
    hd2 <- haver.data(ex_codes2, 'haverd')
    print( identical(as.data.frame(hd), as.data.frame(hd2)) )

    ## or
    ex_codes3 <- haver.dbcodes(database='haverd', format='full')
    hd3 <- haver.data(ex_codes3)
    print( identical(as.data.frame(hd), as.data.frame(hd3)) )

    ## Note, however, that 'haver.dbcodes' does not have the 'histcodes'
    ## parameter that 'haver.metadata' has. For databases that contain series
    ## with frequencies of weekly and higher, if you want to get a proper
    ## series count (i.e., not counting historical component series, see
    ## '?haver.metadata'), you have to resort to 'haver.metadata'.

    haver.path("restore")

[Package Haver version 3.2 Index]