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

Some documentation corrections. Vignette is renamed. Modify error catching in get_data.

parent 970c0cbf
Pipeline #26885 passed with stage
in 6 minutes and 23 seconds
# rdbnomics 0.4.5
* The vignette "rdbnomics-tutorial" is now named "rdbnomics".
* `rdb()` and `rdb_...()` functions now have an argument to configure curl. It
is also an option of the package. The vignette "rdbnomics-tutorial.Rmd" is
is also an option of the package. The vignette "rdbnomics" is
modified consequently.
* `rdb()` and `rdb_by_api_link()` functions return an error if the columns
`period` and `period_start_day` don't exist.
* `rdb()` function passes argument `provider_code` to `ids` if only
`provider_code` is provided. It is considered that the user wants to use
`ids` without naming the arguments.
* `rdb()` function passes argument `ids` to `mask` if only
`provider_code`, `dataset_code` and `ids` are provided. It is considered that
the user wants to use `mask` without naming the argument.
# rdbnomics 0.4.4
* Change of the API version from 21 to 22.
* The vignette "rdbnomics-tutorial.Rmd" is modified to be backward compatible
* The vignette "rdbnomics-tutorial" is modified to be backward compatible
with R Markdown v1 (i.e. without pandoc or rmarkdown).
* The vignette "rdbnomics-tutorial.Rmd" has an appendix.
* The vignette "rdbnomics-tutorial" has an appendix.
* New `rdb_providers()` returns the available providers.
* New `rdb_last_updates()` shows the last updates.
* In the functions, dates and timestamps are transformed using `as.Date()` and
......
......@@ -8,49 +8,58 @@
#' \href{https://api.db.nomics.world/}{DBnomics API} (documentation about
#' the API can be found \href{https://api.db.nomics.world/v22/apidocs}{here}).
#' The code of each series is given on the
#' \href{https://db.nomics.world/}{DBnomics website}.
#' \href{https://db.nomics.world/}{DBnomics website}. \cr\cr
#' In the event that only the argument \code{ids} is provided (and those in the
#' ellipsis \code{...}), the argument name can be dropped. The character string
#' vector is directly passed to \code{ids}. \cr
#' In the same way, if only \code{provider_code}, \code{dataset_code} and
#' \code{mask} are provided then the arguments names can be dropped. The
#' last character string is automatically passed to \code{mask}.
#'
#' @param provider_code Character string. DBnomics code of the provider.
#' @param dataset_code Character string. DBnomics code of the dataset.
#' @param ids Character string. DBnomics code of one or several series.
#' @param dimensions List or character string (single quoted). DBnomics
#' code of one or several dimensions in the specified provider and dataset.
#' @param provider_code Character string (default \code{NULL}). DBnomics code
#' of the provider.
#' @param dataset_code Character string (default \code{NULL}). DBnomics code
#' of the dataset.
#' @param ids Character string (default \code{NULL}). DBnomics code of one or
#' several series.
#' @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 mask Character string. DBnomics code of one or several masks
#' in the specified provider and dataset.
#' @param mask Character string (default \code{NULL}). DBnomics code of one or
#' several masks in the specified provider and dataset.
#' @param verbose Logical (default \code{TRUE}). Show warnings of the function.
#' @param ... Arguments to be passed to \code{\link{rdb_by_api_link}}. These
#' arguments concern proxy configuration. See \code{\link{rdb_by_api_link}}
#' arguments concern connection configuration. See \code{\link{rdb_by_api_link}}
#' for details.
#' @return A \code{data.frame} or a \code{data.table}.
#' @examples
#' \dontrun{
#' ## By ids
#' # Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider:
#' # Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
#' df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
#' # or when no argument names are given (provider_code -> ids)
#' df1 <- rdb('AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
#'
#' # Fetch two series from dataset 'Unemployment rate' (ZUTN) of AMECO provider:
#' # Fetch two series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
#' df2 <- rdb(ids = c('AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN'))
#'
#' # Fetch two series from different datasets of different providers:
#' # Fetch two series from different datasets of different providers :
#' df3 <- rdb(ids = c('AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'IMF/CPI/A.AT.PCPIT_IX'))
#'
#'
#' ## By dimensions
#' # Fetch one value of one dimension from dataset 'Unemployment rate' (ZUTN) of AMECO provider:
#' # Fetch one value of one dimension from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
#' df1 <- rdb('AMECO', 'ZUTN', dimensions = list(geo = "ea12"))
#' # or
#' df1 <- rdb('AMECO', 'ZUTN', dimensions = '{"geo": ["ea12"]}')
#'
#' # Fetch two values of one dimension from dataset 'Unemployment rate' (ZUTN) of AMECO provider:
#' # Fetch two values of one dimension from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
#' df2 <- rdb('AMECO', 'ZUTN', dimensions = list(geo = c("ea12", "dnk")))
#' # or
#' df2 <- rdb('AMECO', 'ZUTN', dimensions = '{"geo": ["ea12", "dnk"]}')
#'
#' # Fetch several values of several dimensions from dataset 'Doing business' (DB) of World Bank:
#' # Fetch several values of several dimensions from dataset 'Doing business' (DB) of World Bank :
#' dim <- list(
#' country = c("DZ", "PE"),
#' indicator = c("ENF.CONT.COEN.COST.ZS", "IC.REG.COST.PC.FE.ZS")
......@@ -65,24 +74,23 @@
#'
#'
#' ## By mask
#' # Fetch one series from dataset 'Consumer Price Index' (CPI) of IMF:
#' # Fetch one series from dataset 'Consumer Price Index' (CPI) of IMF :
#' df1 <- rdb('IMF', 'CPI', mask = 'M.DE.PCPIEC_WT')
#' # or when no argument names are given except provider_code and dataset_code
#' # (ids -> mask)
#' # or when no argument names are given except provider_code and dataset_code (ids -> mask)
#' df1 <- rdb('IMF', 'CPI', 'M.DE.PCPIEC_WT')
#'
#' # Fetch two series from dataset 'Consumer Price Index' (CPI) of IMF:
#' # Fetch two series from dataset 'Consumer Price Index' (CPI) of IMF :
#' df2 <- rdb('IMF', 'CPI', mask = 'M.DE+FR.PCPIEC_WT')
#'
#' # Fetch all series along one dimension from dataset 'Consumer Price Index' (CPI) of IMF:
#' # Fetch all series along one dimension from dataset 'Consumer Price Index' (CPI) of IMF :
#' df3 <- rdb('IMF', 'CPI', mask = 'M..PCPIEC_WT')
#'
#' # Fetch series along multiple dimensions from dataset 'Consumer Price Index' (CPI) of IMF:
#' # Fetch series along multiple dimensions from dataset 'Consumer Price Index' (CPI) of IMF :
#' df4 <- rdb('IMF', 'CPI', mask = 'M..PCPIEC_IX+PCPIA_IX')
#'
#'
#' ## Use a specific proxy to fetch the data
#' # Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider:
#' # Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
#' h <- curl::new_handle(
#' proxy = "<proxy>",
#' proxyport = <port>,
......@@ -96,7 +104,7 @@
#'
#'
#' ## Use R default connection to avoid a proxy failure (in some cases)
#' # Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider:
#' # Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
#' options(rdbnomics.use_readLines = TRUE)
#' df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
#' # or to use once
......@@ -143,7 +151,7 @@ rdb <- function(
# provider_code is considered as ids in some cases
if (
provider_code_not_null & dataset_code_null & dimensions_null & mask_null &
ids_null
ids_null & getOption("rdbnomics.rdb_no_arg")
) {
fcall <- sys.call()
modif_arg <- call_ok(fcall)
......@@ -163,7 +171,7 @@ rdb <- function(
# ids is considered as mask in some cases
if (
provider_code_not_null & dataset_code_not_null & dimensions_null &
mask_null & ids_not_null
mask_null & ids_not_null & getOption("rdbnomics.rdb_no_arg")
) {
fcall <- sys.call()
modif_arg <- call_ok(fcall)
......@@ -187,7 +195,8 @@ rdb <- function(
paste0(
"When you filter with 'dimensions', you must specifiy ",
"'provider_code' and 'dataset_code' as arguments of the function."
)
),
call. = FALSE
)
}
......@@ -207,7 +216,10 @@ rdb <- function(
"?observations=1&dimensions=", dimensions
)
} else {
stop(paste0("Don't know what to do for API version ", api_version, "."))
stop(
paste0("Don't know what to do for API version ", api_version, "."),
call. = FALSE
)
}
return(rdb_by_api_link(api_link = link, ...))
......@@ -220,7 +232,8 @@ rdb <- function(
paste0(
"When you filter with 'mask', you must specifiy 'provider_code' ",
"and 'dataset_code' as arguments of the function."
)
),
call. = FALSE
)
}
......@@ -239,7 +252,10 @@ rdb <- function(
"/", mask, "?observations=1"
)
} else {
stop(paste0("Don't know what to do for API version ", api_version, "."))
stop(
paste0("Don't know what to do for API version ", api_version, "."),
call. = FALSE
)
}
return(rdb_by_api_link(api_link = link, ...))
......@@ -259,10 +275,10 @@ rdb <- function(
}
if (!is.character(ids)) {
stop("'ids' must be of class 'character'.")
stop("'ids' must be of class 'character'.", call. = FALSE)
}
if (length(ids) <= 0) {
stop("'ids' is empty.")
stop("'ids' is empty.", call. = FALSE)
}
if (api_version == 21) {
......@@ -274,11 +290,14 @@ rdb <- function(
api_base_url, "?observations=1&series_ids=", paste(ids, collapse = ",")
)
} else {
stop(paste0("Don't know what to do for API version ", api_version, "."))
stop(
paste0("Don't know what to do for API version ", api_version, "."),
call. = FALSE
)
}
return(rdb_by_api_link(api_link = link, ...))
}
stop("Please provide correct 'dimensions', 'mask' or 'ids'.")
stop("Please provide correct 'dimensions', 'mask' or 'ids'.", call. = FALSE)
}
......@@ -15,22 +15,22 @@
#' through the default R internet connection. This can be used to get round the
#' error \code{Could not resolve host: api.db.nomics.world}.
#' @param curl_config Curl_handle or list (default \code{NULL}). If not
#' \code{NULL}, it is used to set up a specific proxy connection. This
#' \code{NULL}, it is used to configure a proxy connection. This
#' configuration is passed to the function \code{curl_fetch_memory} of the package
#' \pkg{curl}. If it is a \code{curl_handle} object then it is considered to
#' be the argument \code{handle} of \code{curl_fetch_memory}. In the case of a
#' list, the names of the object are the names of the arguments of
#' \code{curl_fetch_memory}. It means that \code{curl_config = h} is
#' equivalent to \code{curl_config = list(handle = h)}.
#' For \code{curl_fetch_memory} arguments see
#' \code{\link[curl]{curl_fetch}}.
#' list, the names of the object are the arguments names of
#' \code{curl_fetch_memory} (except \code{url} of course). It means that
#' \code{curl_config = h} is equivalent to
#' \code{curl_config = list(handle = h)}. \cr
#' For \code{curl_fetch_memory} arguments see \code{\link[curl]{curl_fetch}}.
#' For available curl options see \code{\link[curl]{curl_options}},
#' \code{names(curl_options())} and
#' \href{https://curl.haxx.se/libcurl/c/curl_easy_setopt.html}{libcurl}.
#' @return A \code{data.frame} or a \code{data.table}.
#' @examples
#' \dontrun{
#' # Fetch two series from different datasets of different providers:
#' # Fetch two series from different datasets of different providers :
#' df1 <- rdb_by_api_link(
#' paste0(
#' 'https://api.db.nomics.world/v22/',
......@@ -38,7 +38,7 @@
#' )
#' )
#'
#' # Fetch one series from the dataset 'Doing Business' of WB provider:
#' # Fetch one series from the dataset 'Doing Business' of WB provider :
#' df2 <- rdb_by_api_link(
#' paste0(
#' 'https://api.db.nomics.world/v22/series/WB/DB?dimensions=%7B%22',
......@@ -49,7 +49,7 @@
#'
#'
#' ## Use a specific proxy to fetch the data
#' # Fetch one series from the dataset 'Doing Business' of WB provider:
#' # Fetch one series from the dataset 'Doing Business' of WB provider :
#' h <- curl::new_handle(
#' proxy = "<proxy>",
#' proxyport = <port>,
......@@ -76,7 +76,7 @@
#'
#'
#' ## Use R default connection to avoid a proxy failure (in some cases)
#' # Fetch one series from the dataset 'Doing Business' of WB provider:
#' # Fetch one series from the dataset 'Doing Business' of WB provider :
#' options(rdbnomics.use_readLines = TRUE)
#' df2 <- rdb_by_api_link(
#' paste0(
......@@ -119,7 +119,10 @@ rdb_by_api_link <- function(
} else if (api_version == 22) {
data_elt <- "docs"
} else {
stop(paste0("Don't know what to do for API version ", api_version, "."))
stop(
paste0("Don't know what to do for API version ", api_version, "."),
call. = FALSE
)
}
# If data is empty, return NULL
......@@ -183,8 +186,29 @@ rdb_by_api_link <- function(
transform_date_timestamp(DBdata)
# Modifying column names
data.table::setnames(DBdata, "period", "original_period")
data.table::setnames(DBdata, "period_start_day", "period")
tryCatch({
data.table::setnames(DBdata, "period", "original_period")
}, error = function(e) {
stop(
paste0(
"The retrieved dataset doesn't have a column named 'period', it's not ",
"normal please check <db.nomics.world>."
),
call. = FALSE
)
})
tryCatch({
data.table::setnames(DBdata, "period_start_day", "period")
}, error = function(e) {
stop(
paste0(
"The retrieved dataset doesn't have a column named ",
"'period_start_day', it's not normal please check <db.nomics.world>."
),
call. = FALSE
)
})
DBdata[]
}
......@@ -7,22 +7,22 @@
#' containing the last 100 updates from
#' \href{https://db.nomics.world/}{DBnomics} with additional informations.
#'
#' @param all Logical (default \code{FALSE}). If \code{TRUE}, then the entire
#' @param all Logical (default \code{FALSE}). If \code{TRUE}, then the full
#' dataset of the last updates is retrieved.
#' @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
#' error \code{Could not resolve host: api.db.nomics.world}.
#' @param curl_config Curl_handle or list (default \code{NULL}). If not
#' \code{NULL}, it is used to set up a specific proxy connection. This
#' \code{NULL}, it is used to configure a proxy connection. This
#' configuration is passed to the function \code{curl_fetch_memory} of the package
#' \pkg{curl}. If it is a \code{curl_handle} object then it is considered to
#' be the argument \code{handle} of \code{curl_fetch_memory}. In the case of a
#' list, the names of the object are the names of the arguments of
#' \code{curl_fetch_memory}. It means that \code{curl_config = h} is
#' equivalent to \code{curl_config = list(handle = h)}.
#' For \code{curl_fetch_memory} arguments see
#' \code{\link[curl]{curl_fetch}}.
#' list, the names of the object are the arguments names of
#' \code{curl_fetch_memory} (except \code{url} of course). It means that
#' \code{curl_config = h} is equivalent to
#' \code{curl_config = list(handle = h)}. \cr
#' For \code{curl_fetch_memory} arguments see \code{\link[curl]{curl_fetch}}.
#' For available curl options see \code{\link[curl]{curl_options}},
#' \code{names(curl_options())} and
#' \href{https://curl.haxx.se/libcurl/c/curl_easy_setopt.html}{libcurl}.
......@@ -65,7 +65,7 @@ rdb_last_updates <- function(
data.table::setDT(updates)
if (all) {
sequence <- seq(0, floor(n/lim) * lim, lim)
sequence <- seq(0, floor(n / lim) * lim, lim)
updates <- lapply(sequence, function(x) {
link <- paste0(
api_base_url, "/v", api_version, "/last-updates?datasets.offset=",
......@@ -77,7 +77,10 @@ rdb_last_updates <- function(
updates <- data.table::rbindlist(updates, use.names = TRUE, fill = TRUE)
}
} else {
stop(paste0("Don't know what to do for API version ", api_version, "."))
stop(
paste0("Don't know what to do for API version ", api_version, "."),
call. = FALSE
)
}
transform_date_timestamp(updates)
......
......@@ -15,15 +15,15 @@
#' through the default R internet connection. This can be used to get round the
#' error \code{Could not resolve host: api.db.nomics.world}.
#' @param curl_config Curl_handle or list (default \code{NULL}). If not
#' \code{NULL}, it is used to set up a specific proxy connection. This
#' \code{NULL}, it is used to configure a proxy connection. This
#' configuration is passed to the function \code{curl_fetch_memory} of the package
#' \pkg{curl}. If it is a \code{curl_handle} object then it is considered to
#' be the argument \code{handle} of \code{curl_fetch_memory}. In the case of a
#' list, the names of the object are the names of the arguments of
#' \code{curl_fetch_memory}. It means that \code{curl_config = h} is
#' equivalent to \code{curl_config = list(handle = h)}.
#' For \code{curl_fetch_memory} arguments see
#' \code{\link[curl]{curl_fetch}}.
#' list, the names of the object are the arguments names of
#' \code{curl_fetch_memory} (except \code{url} of course). It means that
#' \code{curl_config = h} is equivalent to
#' \code{curl_config = list(handle = h)}. \cr
#' For \code{curl_fetch_memory} arguments see \code{\link[curl]{curl_fetch}}.
#' For available curl options see \code{\link[curl]{curl_options}},
#' \code{names(curl_options())} and
#' \href{https://curl.haxx.se/libcurl/c/curl_easy_setopt.html}{libcurl}.
......
......@@ -6,7 +6,11 @@
#-------------------------------------------------------------------------------
# get_data
get_data <- function(x, userl, curl_args, run = 0) {
if (run > 0) { Sys.sleep(getOption("rdbnomics.sleep_run")) }
if (run > 0) {
sys_sleep <- getOption("rdbnomics.sleep_run")
check_argument(sys_sleep, c("integer", "numeric"))
Sys.sleep(sys_sleep)
}
tryCatch({
if (userl) {
......@@ -17,7 +21,9 @@ get_data <- function(x, userl, curl_args, run = 0) {
}
}
if (getOption("rdbnomics.verbose_warning_readLines")) {
verb_warn_rl <- getOption("rdbnomics.verbose_warning_readLines")
check_argument(verb_warn_rl, "logical")
if (verb_warn_rl) {
response <- try(readLines(x), silent = TRUE)
} else {
response <- try(suppressWarnings(readLines(x)), silent = TRUE)
......@@ -61,7 +67,10 @@ get_data <- function(x, userl, curl_args, run = 0) {
response <- do.call(curl::curl_fetch_memory, c(list(url = x), curl_args))
check_x <- curl::parse_headers(response$headers)
check_x <- utils::head(check_x, 1)
if (grepl(getOption("rdbnomics.http_ok"), toupper(check_x))) {
http_ok <- getOption("rdbnomics.http_ok")
check_argument(http_ok, "character")
if (grepl(http_ok, toupper(check_x))) {
response <- rawToChar(response$content)
jsonlite::fromJSON(response)
} else {
......@@ -69,7 +78,21 @@ get_data <- function(x, userl, curl_args, run = 0) {
}
}
}, error = function(e) {
if (run < getOption("rdbnomics.try_run")) {
try_run <- getOption("rdbnomics.try_run")
check_argument(try_run, c("integer", "numeric"))
myerror <- try(
grepl("'curl_config'", e$message) |
grepl("BAD[[:blank:]]+REQUEST", toupper(e$message)),
silent = TRUE
)
if (!inherits(myerror, "try-error")) {
if (myerror) {
try_run <- -1L
}
}
if (run < try_run) {
get_data(x, userl, curl_args, run = run + 1)
} else {
stop(e)
......@@ -81,7 +104,7 @@ get_data <- function(x, userl, curl_args, run = 0) {
# deploy
deploy <- function(DT, columns = NULL, reference_column = "value") {
if (!data.table::is.data.table(DT)) {
stop("DT is not a data.table.")
stop("DT is not a data.table.", call. = FALSE)
}
if (nrow(DT) <= 0) { return(DT) }
......@@ -180,7 +203,7 @@ get_version <- function(x) {
} else if ("version" %in% names(x$`_meta`)) {
api_version <- numeric_version(x$`_meta`$version)
} else {
stop("Can't find the version.")
stop("Can't find the version.", call. = FALSE)
}
api_version <- unlist(api_version)
api_version <- api_version[api_version != 0]
......@@ -193,25 +216,28 @@ get_version <- function(x) {
# authorized_version
authorized_version <- function(x) {
versions <- getOption("rdbnomics.authorized_api_version")
check_argument(versions, c("integer", "numeric"), len = FALSE)
name <- deparse(substitute(versions))
if (is.null(versions)) {
stop(paste0(name, " cannot be NULL."))
stop(paste0(name, " cannot be NULL."), call. = FALSE)
}
if (!inherits(versions, c("numeric", "integer"))) {
stop(
paste0(name, " must be of class 'integer' or 'numeric'.")
paste0(name, " must be of class 'integer' or 'numeric'."),
call. = FALSE
)
}
if (length(versions) <= 0) {
stop(paste0(name, " must be of length greater than 0."))
stop(paste0(name, " must be of length greater than 0."), call. = FALSE)
}
if (x %notin% versions) {
stop(
paste0(
"Only versions ", paste0(versions, collapse = ", "), " are supported."
)
),
call. = FALSE
)
}
invisible()
......@@ -248,15 +274,20 @@ timestamp_format <- function(x, y) {
check_argument <- function(x, type, len = TRUE, n = 1, not_null = TRUE) {
name <- deparse(substitute(x))
if (not_null) {
if (is.null(x)) { stop(paste0(name, " cannot be NULL.")) }
if (is.null(x)) { stop(paste0(name, " cannot be NULL."), call. = FALSE) }
}
if (!inherits(x, type)) {
stop(
paste0(name, " must be of class '", paste0(type, collapse = "', '"), "'.")
paste0(
name, " must be of class '", paste0(type, collapse = "', '"), "'."
),
call. = FALSE
)
}
if (len) {
if (length(x) != n) { stop(paste0(name, " must be of length ", n, ".")) }
if (length(x) != n) {
stop(paste0(name, " must be of length ", n, "."), call. = FALSE)
}
}
invisible()
}
......@@ -265,12 +296,16 @@ check_argument <- function(x, type, len = TRUE, n = 1, not_null = TRUE) {
# to_json_if_list
to_json_if_list <- function(x) {
if (inherits(x, "list")) {
if (is.null(names(x))) { stop("The list 'dimensions' must be named.") }
if (length(x) <= 0) { stop("The list 'dimensions' is empty.") }
if (is.null(names(x))) {
stop("The list 'dimensions' must be named.", call. = FALSE)
}
if (length(x) <= 0) {
stop("The list 'dimensions' is empty.", call. = FALSE)
}
nm <- names(x)
nm <- no_empty_char(nm)
if (length(x) != length(nm)) {
stop("All elements of 'dimensions' must be named.")
stop("All elements of 'dimensions' must be named.", call. = FALSE)
}
return(jsonlite::toJSON(x))
}
......@@ -370,4 +405,4 @@ call_ok <- function(x) {
}
modif_arg
}
\ No newline at end of file
}
......@@ -20,13 +20,7 @@
)
# Package options
op <- options()
op.rdbnomics <- list(
rdbnomics = c(
"api_base_url", "api_version", "authorized_api_version", "curl_config",
"http_ok", "sleep_run", "timestamp_tz", "try_run", "use_readLines",
"verbose_warning", "verbose_warning_readLines"
),
opts <- list(
rdbnomics.use_readLines = FALSE,
rdbnomics.sleep_run = 1L,
rdbnomics.try_run = 2L,
......@@ -37,8 +31,17 @@
rdbnomics.verbose_warning_readLines = FALSE,
rdbnomics.timestamp_tz = "GMT",
rdbnomics.http_ok = "200[[:blank:]]+OK$",
rdbnomics.curl_config = NULL
rdbnomics.curl_config = NULL,
rdbnomics.rdb_no_arg = TRUE
)
opts <- append(
opts,
list(rdbnomics = sort(gsub("rdbnomics\\.", "", names(opts)))),
0
)
op <- options()
op.rdbnomics <- opts
toset <- !(names(op.rdbnomics) %in% names(op))
if(any(toset)) options(op.rdbnomics[toset])
invisible()
......
......@@ -27,19 +27,19 @@ library(rdbnomics)
After installation, a vignette is available to the user :
```r
vignette("rdbnomics-tutorial")
vignette("rdbnomics")
```
## Examples
Fetch time series by `ids` :
```r
# Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider:
# Fetch one series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
df1 <- rdb(ids = 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
# Fetch two series from dataset 'Unemployment rate' (ZUTN) of AMECO provider:
# Fetch two series from dataset 'Unemployment rate' (ZUTN) of AMECO provider :
df2 <- rdb(ids = c('AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN'))
# Fetch two series from different datasets of different providers:
# Fetch two series from different datasets of different providers :
df3 <- rdb(ids = c('AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'IMF/CPI/A.AT.PCPIT_IX'))
```
......@@ -50,16 +50,16 @@ df <- rdb('AMECO/ZUTN/EA19.1.0.0.0.ZUTN')
Fetch time series by `mask` :
```r
# Fetch one series from dataset 'Consumer Price Index' (CPI) of IMF:
# Fetch one series from dataset 'Consumer Price Index' (CPI) of IMF :
df1 <- rdb('IMF', 'CPI', mask = 'M.DE.PCPIEC_WT')
# Fetch two series from dataset 'Consumer Price Index' (CPI) of IMF:
# Fetch two series from dataset 'Consumer Price Index' (CPI) of IMF :
df2 <- rdb('IMF', 'CPI', mask = 'M.DE+FR.PCPIEC_WT')