From e23bb66f6bfdc41082843201580318945b427aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20M=C3=A1ty=C3=A1s=20Tam=C3=A1s?= Date: Thu, 14 Mar 2024 15:42:56 +0000 Subject: [PATCH] correction of DSD caching --- DESCRIPTION | 4 ++-- NEWS.md | 4 ++++ R/get_eurostat_dsd.R | 8 ++++---- inst/tinytest/test_restatapi.R | 8 ++++---- man/get_eurostat_dsd.Rd | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2e21d79..3531595 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: restatapi Type: Package Title: Search and Retrieve Data from Eurostat Database -Date: 2024-03-01 -Version: 0.22.8 +Date: 2024-03-14 +Version: 0.22.9 Encoding: UTF-8 Authors@R: c(person("Mátyás", "Mészáros", email = "matyas.meszaros@ec.europa.eu", role = c("aut", "cre")), person("Sebastian", "Weinand", role = "ctb")) diff --git a/NEWS.md b/NEWS.md index b454c47..89a0304 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# restatapi 0.22.9 + +- correction of caching when to DSD downloaded with different languages + # restatapi 0.22.8 - correction when `check_toc=TRUE` option is used diff --git a/R/get_eurostat_dsd.R b/R/get_eurostat_dsd.R index 7a2c1bb..85c67b6 100644 --- a/R/get_eurostat_dsd.R +++ b/R/get_eurostat_dsd.R @@ -2,9 +2,9 @@ #' @description Download Data Structure Definition (DSD) of a Eurostat dataset if it is not cached previously. #' @param id a character string with the id of the dataset. It is a value from the \code{codename} column of the \code{\link{get_eurostat_toc}} function. #' @param lang a character string either \code{en}, \code{de} or \code{fr} to define the language version for the name column of the DSD. It is used only in the new API. The default is \code{en} - English. -#' @param cache a boolean whether to load/save the TOC from/in the cache or not. The default value is \code{TRUE}, so that the TOC is checked first in the cache and if does not exist then downloaded from Eurostat and cached. +#' @param cache a boolean whether to load/save the DSD from/in the cache or not. The default value is \code{TRUE}, so that the DSD is checked first in the cache and if does not exist then downloaded from Eurostat and cached. #' @param update_cache a boolean to update cache or not. The default value is \code{FALSE}, so the cache is not updated. Can be set also with \code{options(restatapi_update=TRUE)} -#' @param cache_dir a path to a cache directory. The default is \code{NULL}, in this case the TOC is cached in the memory (in the '.restatapi_env'). Otherwise if the \code{cache_dir} directory does not exist it creates the 'restatapi' directory in the temporary directory from \code{tempdir()} to save the RDS-file. Directory can also be set with \code{option(restatapi_cache_dir=...)}. +#' @param cache_dir a path to a cache directory. The default is \code{NULL}, in this case the DSD is cached in the memory (in the '.restatapi_env'). Otherwise if the \code{cache_dir} directory does not exist it creates the 'restatapi' directory in the temporary directory from \code{tempdir()} to save the RDS-file. Directory can also be set with \code{option(restatapi_cache_dir=...)}. #' @param compress_file a logical whether to compress the RDS-file in caching. Default is \code{TRUE}. #' @param verbose A boolean with default \code{FALSE}, so detailed messages (for debugging) will not printed. #' Can be set also with \code{options(restatapi_verbose=TRUE)} @@ -65,7 +65,7 @@ get_eurostat_dsd <- function(id, update_cache <- update_cache | getOption("restatapi_update", FALSE) if ((cache) & (!update_cache)) { - dsd<-restatapi::get_eurostat_cache(paste0(id,".dsd"),cache_dir,verbose=verbose) + dsd<-restatapi::get_eurostat_cache(paste0(id,".",lang,".dsd"),cache_dir,verbose=verbose) } if ((!cache)|(is.null(dsd))|(update_cache)){ cfg<-get("cfg",envir=restatapi::.restatapi_env) @@ -226,7 +226,7 @@ get_eurostat_dsd <- function(id, } if (cache){ - pl<-restatapi::put_eurostat_cache(dsd,paste0(id,".dsd"),update_cache,cache_dir,compress_file) + pl<-restatapi::put_eurostat_cache(dsd,paste0(id,".",lang,".dsd"),update_cache,cache_dir,compress_file) if (verbose) {message("get_eurostat_dsd - The DSD of the ",id," dataset was cached ",pl,".")} } } else { diff --git a/inst/tinytest/test_restatapi.R b/inst/tinytest/test_restatapi.R index 716c965..cac50dd 100644 --- a/inst/tinytest/test_restatapi.R +++ b/inst/tinytest/test_restatapi.R @@ -75,7 +75,7 @@ dsd<-get_eurostat_dsd(testid1) if (!is.null(dsd)){ expect_true(data.table::is.data.table(dsd)) # 11 expect_equal(ncol(dsd),3) # 12 - expect_true(exists(paste0(testid1,".dsd"),envir=restatapi::.restatapi_env)) # 13 + expect_true(exists(paste0(testid1,".en.dsd"),envir=restatapi::.restatapi_env)) # 13 } else {not_checked<-paste(not_checked,"11-13",sep=",")} #### test of the search_eurostat_dsd function @@ -192,7 +192,7 @@ if (!is.null(dsd1)&is.data.frame(dsd1)){ } else {not_checked<-paste(not_checked,"45-48",sep=",")} #### test of the get/put_eurostat_cache function -dsd2<-get_eurostat_dsd(testid6) +dsd2<-get_eurostat_dsd(testid6,lang="de") udate<-format(Sys.Date(),"%Y.%m.%d") if (!is.null(xml_toc)) {udate2<-xml_toc$lastUpdate[xml_toc$code==testid5]} else {udate2<-NULL} if (!is.null(rt5)&is.data.frame(rt5)){ @@ -206,10 +206,10 @@ if (!is.null(rt4)&is.data.frame(rt4)){ expect_false(any(sapply(rt4,is.factor))) # 52 } else {not_checked<-paste(not_checked,"51-52",sep=",")} if (!is.null(dsd1)){ - expect_true(exists(paste0(testid4,".dsd"),envir=restatapi::.restatapi_env)) # 53 + expect_true(exists(paste0(testid4,".en.dsd"),envir=restatapi::.restatapi_env)) # 53 } else {not_checked<-paste(not_checked,"53",sep=",")} if (!is.null(dsd2)){ - expect_true(exists(paste0(testid6,".dsd"),envir=restatapi::.restatapi_env)) # 54 + expect_true(exists(paste0(testid6,".de.dsd"),envir=restatapi::.restatapi_env)) # 54 } else {not_checked<-paste(not_checked,"54",sep=",")} expect_false(exists(paste0("b_",testid6,"-",udate,"-0-0-Q"),envir=restatapi::.restatapi_env)) # 55 if (!is.null(rt3)&is.data.frame(rt3)){ diff --git a/man/get_eurostat_dsd.Rd b/man/get_eurostat_dsd.Rd index afdb857..3b4cae5 100644 --- a/man/get_eurostat_dsd.Rd +++ b/man/get_eurostat_dsd.Rd @@ -20,11 +20,11 @@ get_eurostat_dsd( \item{lang}{a character string either \code{en}, \code{de} or \code{fr} to define the language version for the name column of the DSD. It is used only in the new API. The default is \code{en} - English.} -\item{cache}{a boolean whether to load/save the TOC from/in the cache or not. The default value is \code{TRUE}, so that the TOC is checked first in the cache and if does not exist then downloaded from Eurostat and cached.} +\item{cache}{a boolean whether to load/save the DSD from/in the cache or not. The default value is \code{TRUE}, so that the DSD is checked first in the cache and if does not exist then downloaded from Eurostat and cached.} \item{update_cache}{a boolean to update cache or not. The default value is \code{FALSE}, so the cache is not updated. Can be set also with \code{options(restatapi_update=TRUE)}} -\item{cache_dir}{a path to a cache directory. The default is \code{NULL}, in this case the TOC is cached in the memory (in the '.restatapi_env'). Otherwise if the \code{cache_dir} directory does not exist it creates the 'restatapi' directory in the temporary directory from \code{tempdir()} to save the RDS-file. Directory can also be set with \code{option(restatapi_cache_dir=...)}.} +\item{cache_dir}{a path to a cache directory. The default is \code{NULL}, in this case the DSD is cached in the memory (in the '.restatapi_env'). Otherwise if the \code{cache_dir} directory does not exist it creates the 'restatapi' directory in the temporary directory from \code{tempdir()} to save the RDS-file. Directory can also be set with \code{option(restatapi_cache_dir=...)}.} \item{compress_file}{a logical whether to compress the RDS-file in caching. Default is \code{TRUE}.}