Skip to content
Snippets Groups Projects
Commit 2e46d98f authored by Sébastien Galais's avatar Sébastien Galais
Browse files

Correct 'setInternet2' for R version >= R 3.2. Correct cases where names are...

Correct 'setInternet2' for R version >= R 3.2. Correct cases where names are identical in 'rdb_dimensions' and 'get_geo_colname'.
parent d4f2b7d9
No related branches found
No related tags found
No related merge requests found
Pipeline #159197 passed with stage
in 8 minutes and 35 seconds
......@@ -148,6 +148,15 @@ rdb_dimensions <- function(
tmp1 <- as.list(tmp1)
tmp1 <- data.table::data.table(A = unlist(tmp1), B = names(tmp1))
tmp1 <- unique(tmp1)
# Normally column B is in capital letters
if (nrow(tmp1) > 0) {
tmp1[, EQUAL := as.numeric(A == B)]
tmp1[
EQUAL == 1,
A := ifelse(A == capital_first(A), toupper(A), capital_first(A))
]
tmp1[, EQUAL := NULL]
}
}
tmp2 <- tmp$datasets$docs$dimensions_values_labels
......
......@@ -14,7 +14,7 @@ if (getRversion() >= "2.15.1") {
".", ":=", "value", "dotI", "period", "period_start_day", "series_code",
"filtered", "original_period", "series_name", "original_value",
"period_middle_day", "code", "name", "A", "B", "C", "k", "V1", "V2",
"dataset_code"
"dataset_code", "EQUAL"
)
utils::globalVariables(unique(vars))
}
\ No newline at end of file
......@@ -15,9 +15,12 @@ get_data <- function(x, userl, curl_args, headers = NULL, opt = NULL, run = 0) {
tryCatch({
if (userl) {
# Only readLines
if (as.numeric(R.Version()$major) >= 3) {
if (as.numeric(R.Version()$major) == 3) {
if (as.numeric(R.Version()$minor) < 2) {
suppressMessages(suppressWarnings(utils::setInternet2(TRUE)))
try(
suppressMessages(suppressWarnings(utils::setInternet2(TRUE))),
silent = TRUE
)
}
}
......@@ -589,7 +592,20 @@ get_geo_colname <- function(x) {
ref_elt <- gsub(".*\\.", "", z)
elt_ <- gsub('\\.', '"]][["', z)
elt_ <- paste0('[["', elt_, '"]]')
c(codes[i], ref_elt, eval(parse(text = paste0("x", elt_))))
res <- c(codes[i], ref_elt, eval(parse(text = paste0("x", elt_))))
if (length(res) > 0) {
if (res[2] == res[3]) {
if (res[3] == capital_first(res[3])) {
res[3] <- toupper(res[3])
} else {
res[3] <- capital_first(res[3])
}
}
res
} else {
res
}
})
},
silent = TRUE
......
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