Description Usage Arguments Details Value References
Backend functions for communicating with the FRED API
1 2 3 4 5 6 | get.fred(f, url, options=c(), processor=f$processor)
guess.processor(file_type)
basic.json.processor(res, url, options)
smart.json.processor(res, url, options)
basic.xml.processor(res, url, options)
smart.xml.processor(res, url, options)
|
f |
A structure as returned by the |
url |
The API URL to get, relative to the base URL contained in |
options |
A character vector of options to be appended to the URL. |
processor |
A function to be called on the data, or |
file_type |
Data return format, either xml or json. |
res |
Text returned by the web service |
The get.fred
function constructs a URL, gets it, and hands off the response to a processor function. A processor function should take the same arguments as get.fred
, which makes it possible for the processor to differentiate its behavior based on url or options. A few processors are provided (and described below), but other functions tailored to a particular purpose can be plugged in.
The file_type
option determines the format of the response – either xml or json – and of course it only makes sense to use a processor that knows how to handle the specified format. The guess.processor
function takes care of that in the default case by choosing a processor based on file type.
The basic.json.processor, basic.xml.processor
parse JSON/XML into a data.frame
. It does simple classification via type.convert
, but does not bother with dates or other non-atomic types.
The smart.xml.processor
extends basic.xml.processor
by doing date/time classification and returning observations as a zoo
object.
The smart.json.processor
similarly extends basic.json.processor
. Additionally it automatically handles pagination, looking at the request metadata and making additional requests until the total record count is reached. Note that in some cases this may lead to hundreds of thousands of records being retrieved unless a limit is specified explicitly.
The fred
function returns a struct containing basic API settings. All other functions rely on the processor
element of their first argument; return types are dependent on that function.
The official API docs can be found at http://api.stlouisfed.org/docs/fred/. FRED API codes can be obtained from http://api.stlouisfed.org/api_key.html.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.