Commit ab9dff51 authored by Sébastien Galais's avatar Sébastien Galais
Browse files

Reduce vignette size.

parent 035b3889
Package: rdbnomics
Type: Package
Title: Download DBnomics Data
Version: 0.6.0
Version: 0.6.1
Authors@R: c(person("Sebastien", "Galais", role = c("cre", "ctb"),
email = "s915.stem@gmail.com"),
person("Thomas", "Brand", role = c("aut"),
......
# rdbnomics 0.6.1
* New arguments `dimensions` and `query` for the function `rdb_series()`.
# rdbnomics 0.6.0
* New function `rdb_datasets()` to request the available datasets of the
......
......@@ -19,6 +19,12 @@
#' of one or multiple datasets of a provider. If \code{NULL}, the datasets
#' codes are dowloaded with the function \code{\link{rdb_datasets}} and then
#' the series are requested.
#' @param dimensions List or character string (single quoted) (default \code{NULL}).
#' DBnomics code of one or several dimensions in the specified provider and dataset.
#' If it is a named list, then the function \code{toJSON} (from the
#' package \pkg{jsonlite}) is applied to generate the json object.
#' @param query Character string (default \code{NULL}). A query to
#' filter/select series from a provider's dataset.
#' @param use_readLines Logical (default \code{FALSE}). If \code{TRUE}, then
#' the data are requested and read with the base function \code{readLines} i.e.
#' through the default R internet connection. This can be used to get round the
......@@ -44,7 +50,13 @@
#' \dontrun{
#' rdb_series(provider_code = "IMF", dataset_code = "WEO")
#'
#' rdb_series(provider_code = "IMF", dataset_code = "WEO", simplify = TRUE)
#' ## With dimensions
#' rdb_series("IMF", "WEO", dimensions = list(`weo-country` = "AGO"))
#' rdb_series("IMF", "WEO", dimensions = list(`weo-subject` = "NGDP_RPCH"), simplify = TRUE)
#'
#' ## With query
#' rdb_series("IMF", "WEO", query = "ARE")
#' rdb_series("IMF", c("WEO", "WEOAGG"), query = "NGDP_RPCH")
#'
#' rdb_series(provider_code = "IMF", verbose = TRUE)
#'
......@@ -68,6 +80,7 @@
#' @export
rdb_series <- function(
provider_code = NULL, dataset_code = NULL,
dimensions = NULL, query = NULL,
use_readLines = getOption("rdbnomics.use_readLines"),
curl_config = getOption("rdbnomics.curl_config"),
simplify = FALSE, verbose = FALSE,
......@@ -124,6 +137,19 @@ rdb_series <- function(
}
# Checking arguments
query_null <- is.null(query)
query_not_null <- !query_null
if (query_not_null) {
check_argument(query, "character", not_null = FALSE)
}
dimensions_null <- is.null(dimensions)
dimensions_not_null <- !dimensions_null
if (dimensions_not_null) {
dimensions <- to_json_if_list(dimensions)
check_argument(dimensions, c("character", "json"), not_null = FALSE)
}
check_argument(use_readLines, "logical")
check_argument(simplify, "logical")
......@@ -148,7 +174,19 @@ rdb_series <- function(
tryCatch({
dc <- dataset_code[[pc]][i]
api_link <- paste0(api_base_url, "/v", api_version, "/series/", pc, "/", dc)
api_link <- paste0(
api_base_url, "/v", api_version, "/series/", pc, "/", dc
)
if (query_not_null) {
api_link <- paste0(api_link, "?q=", utils::URLencode(query))
}
if (dimensions_not_null) {
api_link <- paste0(
api_link, ifelse(grepl("\\?", api_link), "&", "?"),
"dimensions=", dimensions
)
}
DBlist <- get_data(api_link, use_readLines, curl_config)
limit <- DBlist$series$limit
......
......@@ -139,7 +139,13 @@ df_dimensions <- rdb_dimensions(provider_code = "IMF", dataset_code = "WEO", sim
# Example for the dataset WEOAGG of the IMF:
df_series <- rdb_series(provider_code = "IMF", dataset_code = "WEOAGG")
df_series <- rdb_series(provider_code = "IMF", dataset_code = "WEOAGG", simplify = TRUE)
# With dimensions
df_series <- rdb_series("IMF", "WEO", dimensions = list(`weo-country` = "AGO"))
df_series <- rdb_series("IMF", "WEO", dimensions = list(`weo-subject` = "NGDP_RPCH"), simplify = TRUE)
# With a query
df_series <- rdb_series("IMF", "WEO", query = "ARE")
df_series <- rdb_series("IMF", c("WEO", "WEOAGG"), query = "NGDP_RPCH")
```
:warning: We ask the user to use this function parsimoniously because there are a huge amount
......
......@@ -7,6 +7,8 @@
rdb_series(
provider_code = NULL,
dataset_code = NULL,
dimensions = NULL,
query = NULL,
use_readLines = getOption("rdbnomics.use_readLines"),
curl_config = getOption("rdbnomics.curl_config"),
simplify = FALSE,
......@@ -25,6 +27,14 @@ of one or multiple datasets of a provider. If \code{NULL}, the datasets
codes are dowloaded with the function \code{\link{rdb_datasets}} and then
the series are requested.}
\item{dimensions}{List or character string (single quoted) (default \code{NULL}).
DBnomics code of one or several dimensions in the specified provider and dataset.
If it is a named list, then the function \code{toJSON} (from the
package \pkg{jsonlite}) is applied to generate the json object.}
\item{query}{Character string (default \code{NULL}). A query to
filter/select series from a provider's dataset.}
\item{use_readLines}{Logical (default \code{FALSE}). If \code{TRUE}, then
the data are requested and read with the base function \code{readLines} i.e.
through the default R internet connection. This can be used to get round the
......@@ -70,7 +80,13 @@ containing the series of datasets for providers from
\dontrun{
rdb_series(provider_code = "IMF", dataset_code = "WEO")
rdb_series(provider_code = "IMF", dataset_code = "WEO", simplify = TRUE)
## With dimensions
rdb_series("IMF", "WEO", dimensions = list(`weo-country` = "AGO"))
rdb_series("IMF", "WEO", dimensions = list(`weo-subject` = "NGDP_RPCH"), simplify = TRUE)
## With query
rdb_series("IMF", "WEO", query = "ARE")
rdb_series("IMF", c("WEO", "WEOAGG"), query = "NGDP_RPCH")
rdb_series(provider_code = "IMF", verbose = TRUE)
......
......@@ -540,7 +540,7 @@ df <- rdb(api_link = "https://api.db.nomics.world/v22/series?observations=1&seri
filter(!is.na(value))
```
```{r, eval = TRUE, echo = FALSE}
df <- rdbnomics:::rdbnomics_df012
df <- head(rdbnomics:::rdbnomics_df012, 50)
```
```{r, echo = FALSE}
......@@ -732,22 +732,34 @@ You can download the list of series, and especially their codes, of a dataset's
provider by using the function `rdb_series`. The result is a nested named list
with a `data.table` at the end of each branch. If you define `simplify = TRUE`,
then the result will be a `data.table` not a nested named list.
For example, for the **IMF** provider and the dataset **WEO**, the command is:
For example, for the **IMF** provider and the dataset **WEO**, the command is (onyl first 100):
```{r, eval = FALSE}
rdb_series(provider_code = "IMF", dataset_code = "WEO", simplify = TRUE)
```
```{r, eval = TRUE, echo = FALSE}
rdbnomics:::rdbnomics_df023 %>%
head(100) %>%
display_table()
```
Like the function `rdb()`, you can add features to `rdb_series()`. You can ask for
the series with specific `dimensions`:
```{r, eval = FALSE}
rdb_series(provider_code = "IMF", dataset_code = "WEO", dimensions = list(`weo-subject` = "NGDP_RPCH"), simplify = TRUE)
```
or with a `query`:
```{r, eval = FALSE}
rdb_series(provider_code = "IMF", dataset_code = c("WEO", "WEOAGG"), query = "NGDP_RPCH")
```
<b><font color='red'>&#9888;</font></b> We ask the user to use this function parsimoniously because there are a huge amount
of series per dataset. Please only fetch for one dataset if you need it or
visit the website [https://db.nomics.world](https://db.nomics.world).
For example, for the **IMF** provider, the number of series is:
For example, for the **IMF** provider, the number of series is (only first 5):
```{r, eval = TRUE, echo = FALSE}
rdbnomics:::rdbnomics_df024 %>%
.[order(-`Number of series`)] %>%
head(5) %>%
display_table()
```
......@@ -885,7 +897,7 @@ The content of two columns are modified:
- `series_name`: same as before for original series, but the suffix ` (filtered)` is added for filtered series.
```{r, eval = TRUE, echo = FALSE}
df <- rdbnomics:::rdbnomics_df013
df <- head(rdbnomics:::rdbnomics_df013, 50)
```
```{r, echo = FALSE}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment