From a812d3ebd4f9bc0812cf1846307a08b810305466 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, 22 Feb 2024 13:55:21 +0000 Subject: [PATCH] updates of examples and some corrections --- DESCRIPTION | 4 ++-- NEWS.md | 6 ++++++ R/create_filter_table.R | 2 +- R/extract_data.R | 2 +- R/extract_dsd.R | 4 ++-- R/extract_toc.R | 2 +- R/filter_raw_data.R | 2 +- R/get_compressed_sdmx.R | 1 + R/get_eurostat_bulk.R | 10 +++++----- R/get_eurostat_data.R | 18 +++++++++++------- R/get_eurostat_dsd.R | 5 ++--- R/get_eurostat_raw.R | 13 +++++++++---- R/load_cfg.R | 6 +++--- R/search_eurostat_dsd.R | 2 +- inst/tinytest/test_restatapi.R | 4 ++-- man/create_filter_table.Rd | 2 +- man/extract_data.Rd | 2 +- man/extract_dsd.Rd | 4 ++-- man/extract_toc.Rd | 2 +- man/filter_raw_data.Rd | 2 +- man/get_compressed_sdmx.Rd | 1 + man/get_eurostat_bulk.Rd | 10 +++++----- man/get_eurostat_data.Rd | 15 ++++++++------- man/get_eurostat_dsd.Rd | 5 ++--- man/get_eurostat_raw.Rd | 13 +++++++++---- man/load_cfg.Rd | 2 -- man/search_eurostat_dsd.Rd | 2 +- 27 files changed, 80 insertions(+), 61 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 95e1e9f..20c23aa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: restatapi Type: Package Title: Search and Retrieve Data from Eurostat Database -Date: 2024-01-22 -Version: 0.22.6 +Date: 2024-02-22 +Version: 0.22.7 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 4551b5a..e7bf89c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# restatapi 0.22.7 + +- correction for detection of cores to be able to load the package in WebR +- correction for `date_filter` if there is a `time` value defined under the `filters` parameter +- update of examples to generate relevant output for documentation + # restatapi 0.22.6 - update of link for the possible flag values diff --git a/R/create_filter_table.R b/R/create_filter_table.R index 2737ec0..330bec5 100644 --- a/R/create_filter_table.R +++ b/R/create_filter_table.R @@ -47,7 +47,7 @@ #' rav<-get("rav",envir=restatapi::.restatapi_env) #' } #' \donttest{ -#' options(timeout=2) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) #' dsd<-get_eurostat_dsd("avia_par_me") #' create_filter_table(c("KYIV","hu","Quarterly"),dsd=dsd,exact_match=FALSE,ignore.case=TRUE) #' create_filter_table(c("KYIV","LHBP","Monthly"),dsd=dsd,exact_match=FALSE,name=FALSE) diff --git a/R/extract_data.R b/R/extract_data.R index 46d0730..84b61b8 100644 --- a/R/extract_data.R +++ b/R/extract_data.R @@ -23,7 +23,7 @@ #' url<-paste0("https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/", #' id, #' "?format=sdmx_2.1_structured&compressed=true") -#' options(timeout=2) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) #' sdmx_xml<-get_compressed_sdmx(url,verbose=TRUE) #' xml_leafs<-xml2::xml_find_all(sdmx_xml,".//Series") #' extract_data(xml_leafs[1]) diff --git a/R/extract_dsd.R b/R/extract_dsd.R index e60ed4c..4091d59 100644 --- a/R/extract_dsd.R +++ b/R/extract_dsd.R @@ -30,14 +30,14 @@ #' parse(text=paste0("cfg$DATAFLOW_REFERENCES$'",rav,"'$datastructure[1]")) #' ) #' ) -#' options(timeout=2) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) #' tryCatch({ #' dsd_xml<-xml2::read_xml(dsd_url)}, #' error=function(e){ #' message("Unable to download the xml file.\n",e)}, #' warning=function(w){ #' message("Unable to download the xml file.\n",w)}) -#' if (exists("dsd_xml")) {extract_dsd("GEO",dsd_xml)} +#' if (exists("dsd_xml")) extract_dsd("FREQ",dsd_xml) #' options(timeout=2) #' } diff --git a/R/extract_toc.R b/R/extract_toc.R index 717c265..af22be0 100644 --- a/R/extract_toc.R +++ b/R/extract_toc.R @@ -16,7 +16,7 @@ #' rav<-get("rav",envir=restatapi::.restatapi_env) #' toc_endpoint<-eval(parse(text=paste0("cfg$TOC_ENDPOINT$'",rav,"'$ESTAT$xml"))) #' \donttest{ -#' options(timeout=2) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) #' tryCatch(xml_leafs<-xml2::xml_find_all(xml2::read_xml(toc_endpoint),".//nt:leaf"), #' error = function(e) {xml_leafs<-""}, #' warning = function(w) {xml_leafs<-""}) diff --git a/R/filter_raw_data.R b/R/filter_raw_data.R index 585f0e6..607aed4 100644 --- a/R/filter_raw_data.R +++ b/R/filter_raw_data.R @@ -31,7 +31,7 @@ #' } #' \donttest{ #' id<-"tus_00age" -#' options(timeout=2) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) #' rd<-get_eurostat_raw(id) #' dsd<-get_eurostat_dsd(id) #' ft<-create_filter_table(c("TIME_SP","Hungary",'T'),FALSE,dsd) diff --git a/R/get_compressed_sdmx.R b/R/get_compressed_sdmx.R index aaa2374..f420d77 100644 --- a/R/get_compressed_sdmx.R +++ b/R/get_compressed_sdmx.R @@ -8,6 +8,7 @@ #' @details It is a sub-function to use in the \code{\link{get_eurostat_raw}} and the \code{\link{get_eurostat_data}} functions. #' @return an xml class object with SDMX tags extracted and read from the downloaded file. #' @examples +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) #' id<-"agr_r_milkpr" #' url<-paste0("https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/", #' id, diff --git a/R/get_eurostat_bulk.R b/R/get_eurostat_bulk.R index 36527dc..db098b1 100644 --- a/R/get_eurostat_bulk.R +++ b/R/get_eurostat_bulk.R @@ -71,13 +71,13 @@ #' } #' } #' \donttest{ -#' options(timeout=2) -#' dt<-get_eurostat_bulk("agr_r_milkpr",keep_flags=TRUE) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) +#' head(get_eurostat_bulk("agr_r_milkpr",keep_flags=TRUE)) #' options(restatapi_update=TRUE) -#' dt<-get_eurostat_bulk("avia_par_ee",check_toc=TRUE) -#' dt<-get_eurostat_bulk("avia_par_ee",select_freq="A",verbose=TRUE) +#' head(get_eurostat_bulk("avia_par_ee",check_toc=TRUE)) +#' head(get_eurostat_bulk("avia_par_ee",select_freq="A",verbose=TRUE)) #' options(restatapi_update=FALSE) -#' dt<-get_eurostat_bulk("agr_r_milkpr",cache_dir=tempdir(),compress_file=FALSE,verbose=TRUE) +#' head(get_eurostat_bulk("agr_r_milkpr",cache_dir=tempdir(),compress_file=FALSE,verbose=TRUE)) #' clean_restatapi_cache(cache_dir=tempdir(),verbose=TRUE) #' options(timeout=60) #' } diff --git a/R/get_eurostat_data.R b/R/get_eurostat_data.R index a561bc2..4a6198e 100644 --- a/R/get_eurostat_data.R +++ b/R/get_eurostat_data.R @@ -123,14 +123,14 @@ #' } #' } #' \donttest{ -#' options(timeout=2) -#' dt<-get_eurostat_data("NAMA_10_GDP") -#' dt<-get_eurostat_data("htec_cis3",update_cache=TRUE,check_toc=TRUE) -#' dt<-get_eurostat_data("agr_r_milkpr",cache_dir="/tmp",cflags=TRUE) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) +#' head(get_eurostat_data("NAMA_10_GDP")) +#' head(get_eurostat_data("htec_cis3",update_cache=TRUE,check_toc=TRUE,verbose=TRUE)) +#' head(get_eurostat_data("agr_r_milkpr",cache_dir="/tmp",cflags=TRUE)) #' options(restatapi_update=FALSE) #' options(restatapi_cache_dir=file.path(tempdir(),"restatapi")) -#' dt<-get_eurostat_data("avia_gonc",select_freq="A",cache=FALSE) -#' dt<-get_eurostat_data("agr_r_milkpr",date_filter=2008,keep_flags=TRUE) +#' head(get_eurostat_data("avia_gonc",select_freq="A",cache=FALSE)) +#' head(get_eurostat_data("agr_r_milkpr",date_filter=2008,keep_flags=TRUE)) #' dt<-get_eurostat_data("avia_par_me", #' filters="BE$", #' exact_match=FALSE, @@ -160,7 +160,8 @@ #' currency="MIO_EUR", #' partner="EXT_EU28", #' geo=c("EU28","HU"), -#' stk_flow="BAL"), +#' stk_flow="BAL", +#' time="2015:2020"), #' date_filter="2010:2012", #' select_freq="A", #' label=TRUE, @@ -311,6 +312,9 @@ get_eurostat_data <- function(id, if(rav==2) {dsdorder<-unique(dsd$concept)[1:(length(unique(dsd$concept)))]} if (length(gregexpr("\\.",filters,perl=TRUE)[[1]])!=(length(dsdorder)-1) | length(filters)>1){ + if (!(is.null(names(filters)))) { + if ("time" %in% names(filters)) date_filter<-c(date_filter, unlist(filters["time"])) + } ft<-restatapi::create_filter_table(filters=filters,date_filter=FALSE,dsd=dsd,exact_match=exact_match,verbose=verbose,...) if (nrow(ft)>0){ ft<-unique(ft[ft$code!=FALSE,2:3]) diff --git a/R/get_eurostat_dsd.R b/R/get_eurostat_dsd.R index b35fb8c..7a2c1bb 100644 --- a/R/get_eurostat_dsd.R +++ b/R/get_eurostat_dsd.R @@ -29,9 +29,8 @@ #' } #' } #' \donttest{ -#' options(timeout=2) -#' dsd<-get_eurostat_dsd("med_rd6",lang="de",cache=FALSE,verbose=TRUE) -#' head(dsd) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) +#' head(get_eurostat_dsd("med_rd6",lang="de",cache=FALSE,verbose=TRUE)) #' options(timeout=60) #' } diff --git a/R/get_eurostat_raw.R b/R/get_eurostat_raw.R index 77da6f7..8410ea9 100644 --- a/R/get_eurostat_raw.R +++ b/R/get_eurostat_raw.R @@ -69,11 +69,16 @@ #' } #' } #' \donttest{ -#' options(timeout=2) -#' dt<-get_eurostat_raw("agr_r_milkpr",keep_flags=TRUE) -#' dt<-get_eurostat_raw("avia_par_ee",mode="xml",check_toc=TRUE,update_cache=TRUE) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) +#' head(get_eurostat_raw("agr_r_milkpr",keep_flags=TRUE)) +#' head(get_eurostat_raw("avia_par_ee",mode="xml",check_toc=TRUE,update_cache=TRUE,verbose=TRUE)) #' options(restatapi_update=FALSE) -#' dt<-get_eurostat_raw("avia_par_me",mode="txt",cache_dir=tempdir(),compress_file=FALSE,verbose=TRUE) +#' head(get_eurostat_raw("avia_par_me",mode="txt",melt=FALSE)) +#' head(get_eurostat_raw("avia_par_me", +#' mode="txt", +#' cache_dir=tempdir(), +#' compress_file=FALSE, +#' verbose=TRUE)) #' options(timeout=60) #' } diff --git a/R/load_cfg.R b/R/load_cfg.R index c8ae406..04978fc 100644 --- a/R/load_cfg.R +++ b/R/load_cfg.R @@ -31,7 +31,6 @@ #' In addition, the list of country codes are loaded to the variable \code{cc} (country codes), based on the \href{https://ec.europa.eu/eurostat/ramon/nomenclatures/index.cfm?TargetUrl=LST_NOM_DTL&StrNom=CL_GEO&StrLanguageCode=EN&IntPcKey=42277583&IntResult=1&StrLayoutCode=HIERARCHIC}{Eurostat standard code list} #' @examples #' \donttest{ -#' options(timeout=2) #' load_cfg(parallel=FALSE) #' options(restatapi_dmethod="auto") #' load_cfg(api_version="test",verbose=TRUE,max_cores=FALSE) @@ -39,7 +38,6 @@ #' eu<-get("cc",envir=.restatapi_env) #' eu$EU28 #' eu$EA15 -#' options(timeout=60) #' } @@ -110,7 +108,7 @@ load_cfg<-function(api_version="default",cfg_file="github",load_toc=FALSE,parall )) if (is.null(mem_size)|length(mem_size)==0){mem_size<-0} # if (Sys.info()[['sysname']]=='Windows'){parallel<-FALSE} - if (parallel) { + if (parallel & !is.na(parallel::detectCores())) { if (Sys.info()[['sysname']]=='Windows'){ options(restatapi_cores=1) } else if (max_cores){ @@ -130,6 +128,8 @@ load_cfg<-function(api_version="default",cfg_file="github",load_toc=FALSE,parall options(restatapi_cores=1) } } + } else { + options(restatapi_cores=1) } if (getOption("restatapi_cores")<2){ diff --git a/R/search_eurostat_dsd.R b/R/search_eurostat_dsd.R index 852b7ad..0e4783c 100644 --- a/R/search_eurostat_dsd.R +++ b/R/search_eurostat_dsd.R @@ -34,7 +34,7 @@ #' rav<-get("rav",envir=restatapi::.restatapi_env) #' } #' \donttest{ -#' options(timeout=2) +#' if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2) #' dsd_example<-get_eurostat_dsd("nama_10_gdp",verbose=TRUE) #' search_eurostat_dsd("EU",dsd_example) #' search_eurostat_dsd("EU",dsd_example,ignore.case=TRUE) diff --git a/inst/tinytest/test_restatapi.R b/inst/tinytest/test_restatapi.R index 0b19d56..9f2aea9 100644 --- a/inst/tinytest/test_restatapi.R +++ b/inst/tinytest/test_restatapi.R @@ -291,7 +291,7 @@ message("\n","Are we at home:",at_home()) ################################## -if (grepl("\\.amzn|-aws|5.4.109+",Sys.info()['release'])) { +if (grepl("\\.amzn|-aws|5.4.109+|-azure ",Sys.info()['release'])) { #### additional test of the get_eurostat_dsd function expect_true(system.time({get_eurostat_dsd(testid1)})[3]