Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import changes #1

Merged
merged 31 commits into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4721a10
Merge pull request #152 from antaldaniel/master
antaldaniel Jan 18, 2020
bcc31f7
Merge pull request #154 from antaldaniel/master
antaldaniel Jan 18, 2020
2dbd299
moved imports to firstlib.R
antagomir Jan 18, 2020
c7454f0
cran checks ok
antagomir Jan 18, 2020
da4b737
bibentry PR added after changes
antagomir Jan 18, 2020
5e2e1e8
limited curl::has_internet() to areas where strictly necessary
Jan 20, 2020
51d0773
Merge pull request #155 from cbizzo/devel
antagomir Jan 20, 2020
7caca93
Conversions seems OK
antagomir Jan 20, 2020
76480e9
Fixed get_bibentry bug
antagomir Jan 20, 2020
165930d
testing in travis
antagomir Jan 21, 2020
017970d
Update get_eurostat_json.R
MDTR-CBS Jan 21, 2020
daf62e7
Merge pull request #156 from MDTR-CBS/patch-1
antagomir Jan 21, 2020
9a39d67
some tests requiring online access are now skipped in travis
antagomir Jan 21, 2020
eba1416
bibentry bug fix
antagomir Jan 21, 2020
4b81ce2
problemati has_internet() replaced with user defined check_access_to_…
Jan 23, 2020
ce11d43
provide a message instead of an error
Jan 23, 2020
8d7c731
typos
Jan 23, 2020
06c1fc0
search_eurostat had broke
Jan 23, 2020
d35f1af
Merge branch 'feature/check_internet' into devel
Jan 23, 2020
e753bb4
CRAN checks ok in devel
antagomir Jan 24, 2020
e8bfd3a
sync with devel
antagomir Jan 24, 2020
f6f43a5
checkin trace error seen in vignette.Rmd
antagomir Jan 24, 2020
a7c8fa7
ok
antagomir Jan 24, 2020
25d59a8
closing bracket moved to where is should have been
Jan 24, 2020
0b964e0
cran checks ok now
antagomir Jan 24, 2020
a6eb26d
Merge branch 'master' of github.com:rOpenGov/eurostat into devel
antagomir Jan 24, 2020
567888b
cran checks ok - testing travis
antagomir Jan 24, 2020
a273f30
README
antagomir Jan 25, 2020
b7d74e0
README fix
antagomir Jan 25, 2020
d22d558
html removed from main
antagomir Jan 25, 2020
74dfb25
ok
antagomir Jan 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
inst/extras
# inst/doc
README.Rmd
README.html
index.*

# pkgdown
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: eurostat
Type: Package
Title: Tools for Eurostat Open Data
Date: 2019-12-19
Version: 3.4.20002
Date: 2020-01-20
Version: 3.5.2
Encoding: UTF-8
Authors@R: c(
person("Leo", "Lahti", email = "leo.lahti@iki.fi", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5537-637X")),
Expand All @@ -29,6 +29,7 @@ Imports:
dplyr,
httr,
jsonlite,
lubridate,
RColorBrewer,
readr,
RefManageR,
Expand All @@ -42,7 +43,6 @@ Suggests:
Cairo,
ggplot2,
knitr,
lubridate,
mapproj,
plotrix,
rmarkdown,
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(check_access_to_data)
export(clean_eurostat_cache)
export(cut_to_classes)
export(dic_order)
Expand All @@ -24,6 +25,7 @@ importFrom(RefManageR,toBiblatex)
importFrom(broom,tidy)
importFrom(classInt,classIntervals)
importFrom(countrycode,countrycode)
importFrom(curl,curl_download)
importFrom(dplyr,"%>%")
importFrom(dplyr,filter)
importFrom(dplyr,left_join)
Expand All @@ -35,6 +37,10 @@ importFrom(httr,content)
importFrom(httr,http_error)
importFrom(httr,status_code)
importFrom(jsonlite,fromJSON)
importFrom(lubridate,day)
importFrom(lubridate,dmy)
importFrom(lubridate,month)
importFrom(lubridate,year)
importFrom(methods,as)
importFrom(readr,col_character)
importFrom(readr,read_tsv)
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# eurostat 3.5.1

* internet and proxy setting fixes
* bibentry fix

# eurostat 3.4.1

* Fixed vignette
Expand Down
38 changes: 38 additions & 0 deletions R/check_access_to_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' @title Check access to ec.europe.eu
#' @description Check if R has access to resources at http://ec.europa.eu
#' @export
#' @author Markus Kainu \email{markus.kainu@@kapsi.fi}
#' @return a logical.
#' @examples
#' \dontrun{
#' check_access_to_data()
#' }

check_access_to_data <- function(){
temp <- tempfile()
http_url <- "http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_60M_2006_4326_LEVL_0.geojson"
# If unix use curl::curl_download to test connection
# If windows use download.file with default method 'wininet'
if(.Platform$OS.type == "unix") {
suppressWarnings(
try(
curl::curl_download(http_url, temp, quiet = TRUE, ),
silent = TRUE)
)

} else {
suppressWarnings(
try(
download.file(http_url,
temp,
quiet= TRUE),
silent = TRUE)
)
}
if (is.na(file.info(temp)$size)){
FALSE
}
else{
TRUE
}
}
5 changes: 5 additions & 0 deletions R/firstlib.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#' @importFrom broom tidy
#' @importFrom classInt classIntervals
#' @importFrom countrycode countrycode
#' @importFrom curl curl_download
#' @importFrom dplyr %>%
#' @importFrom dplyr filter
#' @importFrom dplyr mutate
Expand All @@ -14,6 +15,10 @@
#' @importFrom httr http_error
#' @importFrom httr status_code
#' @importFrom jsonlite fromJSON
#' @importFrom lubridate dmy
#' @importFrom lubridate year
#' @importFrom lubridate month
#' @importFrom lubridate day
#' @importFrom methods as
#' @importFrom RColorBrewer brewer.pal
#' @importFrom RefManageR BibEntry
Expand Down
23 changes: 11 additions & 12 deletions R/get_bibentry.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#' @export
#' @author Daniel Antal, Przemyslaw Biecek
#' @return a bibentry, Bibtex or Biblatex object.
#' @importFrom lubridate dmy year month day
#' @examples
#' \dontrun{
#' my_bibliography <- get_bibentry (
Expand Down Expand Up @@ -50,21 +49,22 @@ get_bibentry <- function(
toc <- toc[! duplicated(toc), ]

urldate <- as.character(Sys.Date())
last_update_date <- lubridate::dmy(toc$`last update of data`[i])
last_update_year <- lubridate::year(last_update_date)
last_update_month <- lubridate::month(last_update_date)
last_update_day <- lubridate::day(last_update_date)


if (nrow(toc) == 0) {
if (nrow(toc) == 0) {
warning(paste0("Code ",code, "not found"))
return()
}
}

eurostat_id <- paste0( toc$code, "_",
eurostat_id <- paste0( toc$code, "_",
gsub("\\.", "-", toc$`last update of data`))

for ( i in 1:nrow(toc) ) {
for ( i in 1:nrow(toc) ) {

last_update_date <- lubridate::dmy(toc[["last update of data"]][[i]])
last_update_year <- lubridate::year(last_update_date)
last_update_month <- lubridate::month(last_update_date)
last_update_day <- lubridate::day(last_update_date)


if ( !is.null(keywords) ) { #if user entered keywords
if ( length(keywords)<i ) { #last keyword not entered
Expand Down Expand Up @@ -93,10 +93,9 @@ get_bibentry <- function(
} else {
entries <- entry
}
}
}

if (format == "bibtex") {

entries <- utils::toBibtex(entries)
} else if ( format == "biblatex") {
entries <- RefManageR::toBiblatex ( entries )
Expand Down
13 changes: 8 additions & 5 deletions R/get_eurostat.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@ get_eurostat <- function(id, time_format = "date", filters = "none",
stringsAsFactors = default.stringsAsFactors(),
keepFlags = FALSE, ...){

# Check if you have internet connection
internet_available <- curl::has_internet()
if (!internet_available) stop("You have no internet connection, please reconnect!")

# Check if you have access to ec.europe.eu.
if (!check_access_to_data()){
message("You have no access to ec.europe.eu.
Please check your connection and/or review your proxy settings")
} else {


#Warning for flags with filter
if (keepFlags & !is.character(filters) && filters != "none") {
warning("The keepFlags argument of the get_eurostat function can be used only without filters.
Expand Down Expand Up @@ -209,5 +212,5 @@ get_eurostat <- function(id, time_format = "date", filters = "none",
}

y

}
}
10 changes: 6 additions & 4 deletions R/get_eurostat_geospatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ get_eurostat_geospatial <- function(output_class="sf",resolution="60",
nuts_level = "all", year = "2016",
cache = TRUE, update_cache = FALSE,
cache_dir = NULL){
# Check if you have internet connection
internet_available <- curl::has_internet()
if (!internet_available) stop("You have no internet connection, please reconnect!")
# Check if you have access to ec.europe.eu.
if (!check_access_to_data()){
message("You have no access to ec.europe.eu.
Please check your connection and/or review your proxy settings")
} else {

eurostat_geodata_60_2016 <- NULL
LEVL_CODE <- NULL
Expand Down Expand Up @@ -246,5 +248,5 @@ get_eurostat_geospatial <- function(output_class="sf",resolution="60",
# Adding a `geo` column for easier joins with dplyr
shp$geo <- shp$NUTS_ID
return(shp)

}
}
16 changes: 12 additions & 4 deletions R/get_eurostat_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ get_eurostat_json <- function(id, filters = NULL,
stringsAsFactors = default.stringsAsFactors(),
...){

# Check if you have internet connection
internet_available <- curl::has_internet()
if (!internet_available) stop("You have no internet connection, please reconnect!")
# Check if you have access to ec.europe.eu.
if (!check_access_to_data()){
message("You have no access to ec.europe.eu.
Please check your connection and/or review your proxy settings")
} else {


# get response
# url <- try(eurostat_json_url(id = id, filters = filters, lang = lang))
Expand Down Expand Up @@ -118,7 +121,7 @@ get_eurostat_json <- function(id, filters = NULL,
dat <- data.frame(variables[rev(names(variables))], values = jdat[[1]]$value)

tibble::as_tibble(dat)

}
}


Expand All @@ -140,3 +143,8 @@ eurostat_json_url <- function(id, filters, lang){
url <- httr::build_url(url_list)
url
}





24 changes: 24 additions & 0 deletions R/get_eurostat_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,27 @@ get_eurostat_raw <- function(id) {

dat
}



# #' @title Check if download.file() can access the internet
# #' @description Check if download.file() can access the internet.
# #' @return A Boolean which corresponds to if base function download.file() can access the internet
# #' @author Colm Bates
# #' @examples
# #' \dontrun{
# #' eurostat:::has_internet:::download.file()
# #'
# #' }
#
# has_internet_download.file <- function(){
# temp <- tempfile()
# suppressWarnings(try(download.file("http://captive.apple.com/html", temp, quiet= TRUE), silent = TRUE))
# if (is.na(file.info(temp)$size)){
# FALSE
# }
# else{
# data<- readChar(temp, file.info(temp)$size)
# grepl("Success", readChar(temp, file.info(temp)$size), data)
# }
# }
10 changes: 6 additions & 4 deletions R/label_eurostat.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ label_eurostat <-
custom_dic = NULL,
fix_duplicated = FALSE) {

# Check if you have internet connection
internet_available <- curl::has_internet()
if (!internet_available) stop("You have no internet connection, please reconnect!")
# Check if you have access to ec.europe.eu.
if (!check_access_to_data()){
message("You have no access to ec.europe.eu.
Please check your connection and/or review your proxy settings")
} else {

# Avoid warnings
code_name <- NULL
Expand Down Expand Up @@ -201,7 +203,7 @@ label_eurostat <-


y

}
}

#' @describeIn label_eurostat Get definitions for variable (column) names. For
Expand Down
9 changes: 6 additions & 3 deletions R/search_eurostat.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@
#' @keywords utilities database
search_eurostat <- function(pattern, type = "dataset", fixed = TRUE) {

# Check if you have internet connection
internet_available <- curl::has_internet()
if (!internet_available) stop("You have no internet connection, please reconnect!")
# Check if you have access to ec.europe.eu.
if (!check_access_to_data()){
message("You have no access to ec.europe.eu.
Please check your connection and/or review your proxy settings")
} else {

set_eurostat_toc()
tmp <- get(".eurostatTOC", envir = .EurostatEnv)
if (type != "all") tmp <- tmp[ tmp$type %in% type, ]
tmp[ grep(tmp$title, pattern = pattern, fixed = fixed), ]
}
}


Expand Down
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
title: eurostat R package
output:
html_document:
keep_md: yes
Expand Down
3 changes: 2 additions & 1 deletion README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
title: eurostat R package
output:
html_document:
keep_md: yes
Expand Down Expand Up @@ -57,7 +58,7 @@ Contributions are very welcome:

### Acknowledgements

**Kindly cite this work** as follows: [Leo Lahti](https://github.com/antagomir), Przemyslaw Biecek, Markus Kainu and Janne Huovari. Retrieval and analysis of Eurostat open data with the eurostat package. [R Journal 9(1):385-392, 2017](https://journal.r-project.org/archive/2017/RJ-2017-019/index.html). R package version 3.4.20002. URL: [http://ropengov.github.io/eurostat](http://ropengov.github.io/eurostat)
**Kindly cite this work** as follows: [Leo Lahti](https://github.com/antagomir), Przemyslaw Biecek, Markus Kainu and Janne Huovari. Retrieval and analysis of Eurostat open data with the eurostat package. [R Journal 9(1):385-392, 2017](https://journal.r-project.org/archive/2017/RJ-2017-019/index.html). R package version . URL: [http://ropengov.github.io/eurostat](http://ropengov.github.io/eurostat)

We are grateful to all [contributors](https://github.com/rOpenGov/eurostat/graphs/contributors), including Daniel Antal, Joona Lehtomäki, Francois Briatte, and Oliver Reiter, and for the [Eurostat](https://ec.europa.eu/eurostat/) open data portal! This project is part of [rOpenGov](http://ropengov.github.io).

Expand Down
8 changes: 4 additions & 4 deletions docs/LICENSE-text.html

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

Loading