-
Notifications
You must be signed in to change notification settings - Fork 18
/
README.Rmd
executable file
·104 lines (78 loc) · 2.94 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
# IMFData
[![Build Status](http://travis-ci.org/mingjerli/IMFData.png?branch=master)](https://travis-ci.org/mingjerli/IMFData)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/IMFData)](https://cran.r-project.org/package=IMFData)
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
IMFData is an R package to access [IMF (Internation Monetary Fund) data](http://data.imf.org) . It has three main goals:
* Find out available datasets in the API.
* Find out the dataset datastructure and code to use to make a query.
* Query through the API.
## Installation
Right now, you can install
* from CRAN with
```R
install.packages('IMFData')
```
* the latest development version from github with
```R
devtools::install_github('mingjerli/IMFData')
```
## Loading the package
```{r, cache=TRUE}
library(IMFData)
```
## How to use IMFData
If you don't know anything about [IMF data](http://data.imf.org) API, the following four steps is a good way to start.
### Find out available dataset in [IMF data](http://data.imf.org).
```{r, echo = TRUE, tidy=TRUE, cache=TRUE}
availableDB <- DataflowMethod()
availableDB$DatabaseID
availableDB$DatabaseText
```
### Findout how many dimensions are available in a given dataset. Here, we use IFS(International Financial Statistics) for example,
```{r, echo = TRUE, tidy=TRUE, cache=TRUE}
# Get dimension code of IFS dataset
IFS.available.codes <- DataStructureMethod('IFS')
# Available dimension code
names(IFS.available.codes)
# Possible code in the first dimension
IFS.available.codes[[1]]
```
### Search possible code to use in each dimension. Here, we want to search code related to GDP in CL_INDICATOR_IFS dimension,
```{r, echo = TRUE, tidy=TRUE, cache=TRUE}
# Search code contains GDP
CodeSearch(IFS.available.codes, 'CL_INDICATOR_IFS', 'GDP')
```
### Make API call to get data
```{r, echo = TRUE, tidy=TRUE, cache=TRUE}
databaseID <- 'IFS'
startdate='2001-01-01'
enddate='2016-12-31'
checkquery = FALSE
## Germany, Norminal GDP in Euros, Norminal GDP in National Currency
queryfilter <- list(CL_FREA="", CL_AREA_IFS="GR", CL_INDICATOR_IFS =c("NGDP_EUR","NGDP_XDC"))
GR.NGDP.query <- CompactDataMethod(databaseID, queryfilter, startdate, enddate, checkquery)
GR.NGDP.query[,1:5]
GR.NGDP.query$Obs[[1]]
GR.NGDP.query$Obs[[2]]
## Quarterly, US, NGDP_SA_AR_XDC
queryfilter <- list(CL_FREA="Q", CL_AREA_IFS="US", CL_INDICATOR_IFS ="NGDP_SA_AR_XDC")
Q.US.NGDP.query <- CompactDataMethod(databaseID, queryfilter, startdate, enddate, checkquery)
Q.US.NGDP.query[,1:5]
Q.US.NGDP.query$Obs[[1]]
## See exact API call to the data source
CompactDataMethod(databaseID, queryfilter, startdate, enddate, checkquery, verbose=TRUE)$Obs[[1]]
## Return a simple data frame
head(CompactDataMethod(databaseID, queryfilter, startdate, enddate, checkquery, tidy=TRUE))
```