Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Reu-hub committed May 25, 2024
1 parent 2554ddf commit 936568e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 104 deletions.
5 changes: 3 additions & 2 deletions R/ids_query_data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
utils::globalVariables(c("data_last_updated","api_code", "wb_creditor_name", "wb_debtor_country_name"))

#' ids_query_data
#' Gets debt information for a given country (debtor) that it owes to any creditor.
#' @title Query debt data
#' @description
#' Query debt information for a given country (debtor) that it owes to any creditor.
#' The default creditors are both China and the World
#'
#' @param etl_object An `etl` object
Expand Down
67 changes: 30 additions & 37 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ unique_time %>% head() %>% kable()
We create an ETL object by specifying a string that defines the object's class, and use the package `idswb` to gain access to the relevant data.
```{r}
# ceating an object
idswb_ob <-etl("idswb", dir = getwd())
# idswb_ob <-etl("idswb", dir = getwd())
```

Expand All @@ -114,7 +114,7 @@ idswb_ob <-etl("idswb", dir = getwd())

The first step here is to acquire data
```{r}
idswb_ob %>% etl_extract()
# idswb_ob %>% etl_extract()
```

```{r}
Expand All @@ -124,7 +124,7 @@ idswb_ob %>% etl_extract()

This data might require conversion from its original format into files that are appropriate for SQL import, typically in CSV format.
```{r}
idswb_ob %>% etl_transform()
# idswb_ob %>% etl_transform()
```

```{r}
Expand All @@ -134,14 +134,14 @@ idswb_ob %>% etl_transform()

Fill the SQL database with the processed data.
```{r}
idswb_ob %>% etl_load()
# idswb_ob %>% etl_load()
```

```{r}
```
We can still perform the steps above at once
```{r eval=FALSE}
```{r message = FALSE, warning=FALSE}
# ceating an object
idswb_ob <-etl("idswb", dir = getwd())
Expand All @@ -156,6 +156,10 @@ idswb_ob %>%

```{r}
```
## Using etl_create method
```{r}
# idswb_ob %>% etl_create()
```

```{r}
Expand All @@ -167,46 +171,35 @@ We can now query debt of a given country that it owes to both China and the Worl

`Query 1:`
```{r}
dplyr::tbl(idswb_ob, "ids_wb") %>%
# query data
dplyr::filter(wb_debtor_country_name == "Kenya",
wb_creditor_name %in% c("China","World"),
api_code %in% c("DT.DOD.BLAT.CD",
"DT.DOD.PBND.CD",
'DT.DOD.MLAT.CD',
"DT.DOD.PROP.CD",
"DT.DOD.PCBK.CD",
"DT.DOD.DPPG.CD")) %>%
dplyr::collect() %>%
# gather data
gather(key = year,value = debt,-c(api_code, data_last_updated, series_full_name, wb_debtor_country_name, wb_debtor_country_id,
wb_creditor_name, wb_creditor_id)) %>%
filter(year == 2022) %>%
mutate(data_last_updated = as_datetime(as.numeric(data_last_updated))) %>%
# inputs specificatio
series <- c("DT.DOD.BLAT.CD","DT.DOD.PBND.CD",'DT.DOD.MLAT.CD',"DT.DOD.PROP.CD","DT.DOD.PCBK.CD","DT.DOD.DPPG.CD")
debtor <- "Kenya"
creditor <- c("China","World")
# Querying data
ids_query_data(etl_object = idswb_ob, debtor = debtor, creditor = creditor, series = series) %>%
filter(year == "2022") %>%
knitr::kable()
```

```{r}
```
`Query 2:`
```{r}
dplyr::tbl(idswb_ob, "ids_wb") %>%
# query data
dplyr::filter(wb_debtor_country_name == "Nigeria",
wb_creditor_name %in% c("China","World"),
api_code %in% c("DT.DOD.BLAT.CD",
"DT.DOD.PBND.CD",
'DT.DOD.MLAT.CD',
"DT.DOD.PROP.CD",
"DT.DOD.PCBK.CD",
"DT.DOD.DPPG.CD")) %>%
dplyr::collect() %>%
# gather data
gather(key = year,value = debt,-c(api_code, data_last_updated, series_full_name, wb_debtor_country_name, wb_debtor_country_id,
wb_creditor_name, wb_creditor_id)) %>%
filter(year == 2022) %>%
mutate(data_last_updated = as_datetime(as.numeric(data_last_updated))) %>%
# inputs specificatio
series <- c("DT.DOD.BLAT.CD","DT.DOD.PBND.CD",'DT.DOD.MLAT.CD',"DT.DOD.PROP.CD","DT.DOD.PCBK.CD","DT.DOD.DPPG.CD")
debtor <- "Nigeria"
creditor <- c("China","World")
# Querying data
ids_query_data(etl_object = idswb_ob, debtor = debtor, creditor = creditor, series = series) %>%
filter(year == "2022") %>%
knitr::kable()
```

```{r}
```

Loading

0 comments on commit 936568e

Please sign in to comment.