Skip to content

Commit

Permalink
updates of examples and some corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyi committed Feb 22, 2024
1 parent 62937ba commit a812d3e
Show file tree
Hide file tree
Showing 27 changed files with 80 additions and 61 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-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 = "[email protected]", role = c("aut", "cre")),
person("Sebastian", "Weinand", role = "ctb"))
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/create_filter_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/extract_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions R/extract_dsd.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#' }

Expand Down
2 changes: 1 addition & 1 deletion R/extract_toc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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<-""})
Expand Down
2 changes: 1 addition & 1 deletion R/filter_raw_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions R/get_compressed_sdmx.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions R/get_eurostat_bulk.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#' }
Expand Down
18 changes: 11 additions & 7 deletions R/get_eurostat_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand Down
5 changes: 2 additions & 3 deletions R/get_eurostat_dsd.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#' }

Expand Down
13 changes: 9 additions & 4 deletions R/get_eurostat_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#' }

Expand Down
6 changes: 3 additions & 3 deletions R/load_cfg.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
#' 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)
#' load_cfg()
#' eu<-get("cc",envir=.restatapi_env)
#' eu$EU28
#' eu$EA15
#' options(timeout=60)
#' }


Expand Down Expand Up @@ -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){
Expand All @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion R/search_eurostat_dsd.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions inst/tinytest/test_restatapi.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]<system.time({get_eurostat_dsd(testid1,update_cache=TRUE,parallel=FALSE,api_version=api_version)})[3]) # a0
Expand Down Expand Up @@ -374,7 +374,7 @@ if (grepl("\\.amzn|-aws|5.4.109+",Sys.info()['release'])) {
} else {not_checked<-paste(not_checked,"a21",sep=",")}
dsd4<-get_eurostat_dsd(testid10)
if (!is.null(dsd4)&is.data.frame(dsd4)){
nr12<-nrow(get_eurostat_data(testid10,filters=list(bop_item="SC",currency="MIO_EUR",partner="EXT_EU28",geo=c("EU28","HU"),time="2010:2017",stk_flow="BAL"),date_filter="2010:2012",select_freq="A",label=TRUE,name=FALSE))
nr12<-nrow(get_eurostat_data(testid10,filters=list(bop_item="SC",currency="MIO_EUR",partner="EXT_EU28",geo=c("EU28","HU"),time="2015:2017",stk_flow="BAL"),date_filter="2010:2012",select_freq="A",label=TRUE,name=FALSE))
if (!is.null(nr12)){
expect_equal(nr12,6) # a22
} else {not_checked<-paste(not_checked,"a22",sep=",")}
Expand Down
2 changes: 1 addition & 1 deletion man/create_filter_table.Rd

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

2 changes: 1 addition & 1 deletion man/extract_data.Rd

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

4 changes: 2 additions & 2 deletions man/extract_dsd.Rd

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

2 changes: 1 addition & 1 deletion man/extract_toc.Rd

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

2 changes: 1 addition & 1 deletion man/filter_raw_data.Rd

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

1 change: 1 addition & 0 deletions man/get_compressed_sdmx.Rd

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

10 changes: 5 additions & 5 deletions man/get_eurostat_bulk.Rd

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

15 changes: 8 additions & 7 deletions man/get_eurostat_data.Rd

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

5 changes: 2 additions & 3 deletions man/get_eurostat_dsd.Rd

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

13 changes: 9 additions & 4 deletions man/get_eurostat_raw.Rd

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

2 changes: 0 additions & 2 deletions man/load_cfg.Rd

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

Loading

0 comments on commit a812d3e

Please sign in to comment.