Skip to content

Commit

Permalink
correction of DSD caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyi committed Mar 14, 2024
1 parent 4d574f1 commit e23bb66
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre")),
person("Sebastian", "Weinand", role = "ctb"))
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions R/get_eurostat_dsd.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions inst/tinytest/test_restatapi.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)){
Expand All @@ -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)){
Expand Down
4 changes: 2 additions & 2 deletions man/get_eurostat_dsd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e23bb66

Please sign in to comment.