Skip to content

Commit

Permalink
correction of unzip for read-only dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyi committed Sep 14, 2021
1 parent 22cd7ea commit a4f44f4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]", role = c("aut", "cre"))
Description: Eurostat is the statistical office of the European Union and provides high quality statistics for Europe.
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.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
Expand Down
3 changes: 2 additions & 1 deletion R/extract_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
#' }
#' }
#'
Expand Down
7 changes: 4 additions & 3 deletions R/get_compressed_sdmx.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,24 @@ 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"))
},
warning = function(w) {
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) {})
}
}
}
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)
}
3 changes: 2 additions & 1 deletion man/extract_data.Rd

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

0 comments on commit a4f44f4

Please sign in to comment.