-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
148 lines (109 loc) · 7.48 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
output: github_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
comment=NA,
eval = FALSE,
fig.path = "man/figures/")
# options(tibble.width = Inf)
# pkgdown::build_site()
```
# quantec <img src="man/figures/logo.png" align="right" alt="" width="120" />
[](https://www.tidyverse.org/lifecycle/#experimental)
[](https://github.com/Bureau-for-Economic-Research/quantec/commits/develop)
The [quantec](https://github.com/Bureau-for-Economic-Research/quantec) library is a _basic_ wrapper around the [EasyData data portal](https://www.easydata.co.za/) API from Quantec maintained by the [Bureau for Economic Research](https://www.ber.ac.za/home/).
This is the homepage for the {quantec} R package <https://github.com/Bureau-for-Economic-Research/quantec>.
**NOTE:** The API is currently in _BETA_ testing.
`r emo::ji("bulb")` Please be a good digital citizen when interacting with an API - restrict parallel implementation and institute sleeps between calling data.
## Disclaimer
This package is no way endorsed by [Quantec](https://www.easydata.co.za/) and was developed at the [Bureau for Economic Research](https://www.ber.ac.za/home/) in order to streamline research process.
## About Qauntec
**From the Quantec Website**
Quantec is a consultancy providing economic and financial data, country intelligence and quantitative analytical software.
Please reach out to [Quantec](https://www.easydata.co.za/) via their Contact Page <https://www.quantec.co.za/contact/> to receive an API key.
## Installation
Install from GitHub.
```{r eval=FALSE}
remotes::install_github("Bureau-for-Economic-Research/quantec")
```
## Usage
```{r load-package, eval = TRUE}
library(quantec)
```
Check version.
```{r check-version}
packageVersion("quantec")
```
### Set API Key
To access the API you'll need to first specify an API in your `.Renviron` key as provided to you by [Quantec](https://www.easydata.co.za/). (`usethis::edit_r_environ()`)
* `.Renviron`
```{txt}
QUANTEC_API=place_your_key_here
```
After setting the API key in `.Renviron`, remember to restart R: `ctrl + shift + F10`.
* In R
```{r}
Sys.setenv(QUANTEC_API="place_your_key_here")
Sys.getenv("QUANTEC_API")
```
# The API interface
The package currently provides an interface to the [Quantec](https://www.easydata.co.za/) data API. The function `quantec_get_data` has the following options:
* `time_series_code` time series code to return, `NMS-EC_BUS,NMS-GA_BUS`
* `freq` frequency to return `M`, `Q` or `A`
* `start_year` year to start (OPTIONAL)
* `end_year` year to end (OPTIONAL)
* `log_file` log file to output to
```{r}
library(quantec)
library(logger)
quantec_get_data(time_series_code = "NMS-EC_BUS",
freq = "A",
start_year = 2000,
end_year = 2022)
# A tibble: 29 × 6
# title unit source code date value
# <chr> <chr> <chr> <chr> <date> <dbl>
# 1 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1994-12-31 10
# 2 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1995-12-31 7
# 3 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1996-12-31 28
# 4 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1997-12-31 70
# 5 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1998-12-31 7
# 6 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1999-12-31 3
# 7 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 2000-12-31 6
# 8 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 2001-12-31 25
# 9 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 2002-12-31 53
# 10 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 2003-12-31 17
# ℹ 19 more rows
# ℹ Use `print(n = ...)` to see more rows
```
If you want to turn on the logging:
```{r}
library(quantec)
library(logger)
log_threshold(level = DEBUG)
quantec_get_data(time_series_code = "NMS-EC_BUS",
freq = "A",
start_year = 2000,
end_year = 2022)
# DEBUG [2023-09-20 14:10:46] [NMS-EC_BUS] -- Querying with parameters: # [{"timeSeriesCodes":["NMS-EC_BUS"],"respFormat":["csv"],"freqs":["A"],"startYear":[2000],"endYear":[2022],"isTidy":[true]}]
# DEBUG [2023-09-20 14:10:46] [NMS-EC_BUS] -- Found 29 rows
# A tibble: 29 × 6
# title unit source code date value
# <chr> <chr> <chr> <chr> <date> <dbl>
# 1 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1994-12-31 10
# 2 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1995-12-31 7
# 3 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1996-12-31 28
# 4 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1997-12-31 70
# 5 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1998-12-31 7
# 6 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 1999-12-31 3
# 7 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 2000-12-31 6
# 8 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 2001-12-31 25
# 9 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 2002-12-31 53
# 10 SACU domestic sales - South Africa - Eastern Cape: Bus sales (> 8,500kg) Number (Sum of Monthly Values) NAAMSA NMS-EC_BUS-SAN 2003-12-31 17
# ℹ 19 more rows
# ℹ Use `print(n = ...)` to see more rows
```