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

'get_data' better handles errors.

parent 7a7c0ec4
Pipeline #155519 passed with stage
in 8 minutes and 54 seconds
# rdbnomics 0.6.2
* Remove **ggplot2**, **DT** and **dplyr** vignette dependencies.
* Internal function `get_data` better handles errors.
# rdbnomics 0.6.1
......
......@@ -336,23 +336,25 @@
# Additional informations translations
if (!is.null(additional_geo_column) & !is.null(additional_geo_mapping)) {
for (i in seq_along(additional_geo_mapping)) {
addcol <- additional_geo_column[[i]][3]
suffix <- ""
if (addcol %in% colnames(DBdata)) {
suffix <- "_add"
newcol <- paste0(addcol, suffix)
setnames(additional_geo_mapping[[i]], addcol, newcol)
}
DBdata <- merge(
DBdata, additional_geo_mapping[[i]],
by = c("dataset_code", additional_geo_column[[i]][2]),
all.x = TRUE, all.y = FALSE, sort = FALSE, allow.cartesian = FALSE
)
if (additional_geo_column[[i]][2] %in% colnames(DBdata)) {
addcol <- additional_geo_column[[i]][3]
suffix <- ""
if (addcol %in% colnames(DBdata)) {
suffix <- "_add"
newcol <- paste0(addcol, suffix)
setnames(additional_geo_mapping[[i]], addcol, newcol)
}
DBdata <- merge(
DBdata, additional_geo_mapping[[i]],
by = c("dataset_code", additional_geo_column[[i]][2]),
all.x = TRUE, all.y = FALSE, sort = FALSE, allow.cartesian = FALSE
)
if (suffix != "") {
DBdata[, (addcol) := ifelse(is.na(get(newcol)), get(addcol), get(newcol))]
DBdata[, (newcol) := NULL]
if (suffix != "") {
DBdata[, (addcol) := ifelse(is.na(get(newcol)), get(addcol), get(newcol))]
DBdata[, (newcol) := NULL]
}
}
}
}
......
......@@ -89,12 +89,22 @@ get_data <- function(x, userl, curl_args, headers = NULL, opt = NULL, run = 0) {
response <- rawToChar(response$content)
if (!is.null(jsonlite::fromJSON(response)$errors)) {
cat("\n")
for (ie in 1:nrow(jsonlite::fromJSON(response)$errors)) {
cat(
jsonlite::fromJSON(response)$errors[ie,]$message, " : ",
jsonlite::fromJSON(response)$errors[ie,]$provider_code, "/",
jsonlite::fromJSON(response)$errors[ie,]$dataset_code, "/",
jsonlite::fromJSON(response)$errors[ie,]$series_code,
"\n"
)
}
}
if (jsonlite::fromJSON(response)$series$num_found <= 0) {
run <- 100
stop(
"\n",
jsonlite::fromJSON(response)$errors$message, " : ",
jsonlite::fromJSON(response)$errors$provider_code, "/",
jsonlite::fromJSON(response)$errors$dataset_code, "/",
jsonlite::fromJSON(response)$errors$series_code,
"Error when fetching the data.",
call. = 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