diff --git a/DESCRIPTION b/DESCRIPTION index 7cfa653..f66acdc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: restatapi Type: Package Title: Search and Retrieve Data from Eurostat Database Date: 2021-09-10 -Version: 0.11.1 +Version: 0.11.2 Encoding: UTF-8 Authors@R: person("Mátyás", "Mészáros", email = "matyas.meszaros@ec.europa.eu", role = c("aut", "cre")) Description: Eurostat is the statistical office of the European Union and provides high quality statistics for Europe. diff --git a/NEWS.md b/NEWS.md index c1df8a3..3416e9f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# restatapi 0.11.2 + +- unzipping to a temporary directory in order to avoid error by read-only user directory + # restatapi 0.11.1 - correction of tests when the TOC is corrupted diff --git a/R/extract_data.R b/R/extract_data.R index fe4a456..79001fb 100644 --- a/R/extract_data.R +++ b/R/extract_data.R @@ -24,10 +24,11 @@ #' if (!is.null(bulk_url)){ #' temp<-tempfile() #' download.file(bulk_url,temp) -#' sdmx_xml<-xml2::read_xml(unzip(temp, paste0(id,".sdmx.xml"))) +#' sdmx_xml<-xml2::read_xml(unzip(temp,paste0(id,".sdmx.xml"),exdir=tempdir())) #' xml_leafs<-xml2::xml_find_all(sdmx_xml,".//data:Series") #' extract_data(xml_leafs[1]) #' unlink(temp) +#' unlink(file.path(tempdir(),paste0(id,".sdmx.xml"))) #' } #' } #' diff --git a/R/get_compressed_sdmx.R b/R/get_compressed_sdmx.R index d7acc5e..afc32c5 100644 --- a/R/get_compressed_sdmx.R +++ b/R/get_compressed_sdmx.R @@ -44,8 +44,9 @@ get_compressed_sdmx<-function(url=NULL,verbose=FALSE){ } else { fajl<-paste0("DataResponse-",sub("^.*\\/","",url,perl=TRUE)) } + tmpdir<-tempdir() if (verbose) { - tryCatch({xml_fajl<-utils::unzip(temp,paste0(fajl,".xml"))}, + tryCatch({xml_fajl<-utils::unzip(temp,paste0(fajl,".xml"),exdir=tmpdir)}, error = function(e) { message("get_compressed_sdmx - Error during the unzip of the SDMX file:",'\n',paste(unlist(e),collapse="\n")) }, @@ -53,7 +54,7 @@ get_compressed_sdmx<-function(url=NULL,verbose=FALSE){ message("get_compressed_sdmx - Warning by the unzip of the SDMX file:",'\n',paste(unlist(w),collapse="\n")) }) } else { - tryCatch({xml_fajl<-utils::unzip(temp,paste0(fajl,".xml"))}, + tryCatch({xml_fajl<-utils::unzip(temp,paste0(fajl,".xml"),exdir=tmpdir)}, error = function(e) {}, warning = function(w) {}) } @@ -61,6 +62,6 @@ get_compressed_sdmx<-function(url=NULL,verbose=FALSE){ } if (!is.null(xml_fajl)){xml<-xml2::read_xml(xml_fajl)} else {xml<-NULL} unlink(temp) - unlink(paste0(fajl,".xml")) + unlink(file.path(tmpdir,paste0(fajl,".xml"))) return(xml) } \ No newline at end of file diff --git a/man/extract_data.Rd b/man/extract_data.Rd index 2a801d4..282dc85 100644 --- a/man/extract_data.Rd +++ b/man/extract_data.Rd @@ -41,10 +41,11 @@ bulk_url<-toc$downloadLink.sdmx[toc$code==id] if (!is.null(bulk_url)){ temp<-tempfile() download.file(bulk_url,temp) - sdmx_xml<-xml2::read_xml(unzip(temp, paste0(id,".sdmx.xml"))) + sdmx_xml<-xml2::read_xml(unzip(temp,paste0(id,".sdmx.xml"),exdir=tempdir())) xml_leafs<-xml2::xml_find_all(sdmx_xml,".//data:Series") extract_data(xml_leafs[1]) unlink(temp) + unlink(file.path(tempdir(),paste0(id,".sdmx.xml"))) } }