diff --git a/R/get_eurostat_json.R b/R/get_eurostat_json.R index 893627f9..eb76ca34 100755 --- a/R/get_eurostat_json.R +++ b/R/get_eurostat_json.R @@ -60,16 +60,17 @@ get_eurostat_json <- function(id, filters = NULL, status <- httr::status_code(resp) # check status and get json + msg <- ". Some datasets are not accessible via the eurostat interface. You can try to search the data manually from the comext database at http://epp.eurostat.ec.europa.eu/newxtweb/ or bulk download facility at http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing or annual Excel files http://ec.europa.eu/eurostat/web/prodcom/data/excel-files-nace-rev.2" if (status == 200){ jdat <- jsonlite::fromJSON(url) } else if (status == 400){ stop("Failure to get data. Probably invalid dataset id. Status code: ", - status) + status, msg) } else if (status == 500){ stop("Failure to get data. Probably filters did not return any data - or data exceeded query size limitation. Status code: ", status) + or data exceeded query size limitation. Status code: ", status, msg) } else { - stop("Failure to get data. Status code: ", status) + stop("Failure to get data. Status code: ", status, msg) } # get json data diff --git a/R/get_eurostat_raw.R b/R/get_eurostat_raw.R index 620ecc35..fa30ce64 100755 --- a/R/get_eurostat_raw.R +++ b/R/get_eurostat_raw.R @@ -35,11 +35,14 @@ get_eurostat_raw <- function(id) { col_types = readr::cols(.default = readr::col_character())) # check validity + if (ncol(dat) < 2 | nrow(dat) < 1) { + msg <- ". Some datasets are not accessible via the eurostat interface. You can try to search the data manually from the comext database at http://epp.eurostat.ec.europa.eu/newxtweb/ or bulk download facility at http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing or annual Excel files http://ec.europa.eu/eurostat/web/prodcom/data/excel-files-nace-rev.2" if (grepl("does not exist or is not readable", dat[1])) { - stop(id, " does not exist or is not readable") + + stop(id, " does not exist or is not readable", msg) } else { - stop(paste("Could not download ", id)) + stop(paste("Could not download ", id, msg)) } } diff --git a/docs/articles/blogposts.html b/docs/articles/blogposts.html index 765e1d5f..c42155e3 100755 --- a/docs/articles/blogposts.html +++ b/docs/articles/blogposts.html @@ -83,7 +83,7 @@
blogposts.Rmd
cheatsheet.Rmd
eurostat_tutorial.Rmd
## Table tgs00026 cached at /tmp/RtmpFlVxl1/eurostat/tgs00026_raw_code_FF.rds
-# Download geospatial data from CISGO
+## Table tgs00026 cached at /tmp/Rtmpabr3HV/eurostat/tgs00026_raw_code_FF.rds
+# Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "sf", resolution = "60")
##
## COPYRIGHT NOTICE
@@ -928,17 +928,22 @@
library(sf)
library(RColorBrewer)
-# Downloading and manipulating the tabular data
-euro_sf2 <- eurostat::get_eurostat("tgs00026", time_format = "raw", stringsAsFactors = FALSE) %>%
- # subsetting to year 2014 and NUTS-3 level
- dplyr::filter(time == 2014, grepl("PL",geo)) %>%
+# Downloading and manipulating the tabular data
+print("Let us focus on year 2014 and NUTS-3 level")
## [1] "Let us focus on year 2014 and NUTS-3 level"
+euro_sf2 <- get_eurostat("tgs00026", time_format = "raw",
+ stringsAsFactors = FALSE,
+ filter = list(time = "2014")) %>%
+
+ # Subset to NUTS-3 level
+ dplyr::filter(grepl("PL",geo)) %>%
# label the single geo column
mutate(label = paste0(label_eurostat(.)[["geo"]], "\n", values, "€"),
- income = cut_to_classes(values))
## Reading cache file /tmp/RtmpFlVxl1/eurostat/tgs00026_raw_code_FF.rds
-## Table tgs00026 read from cache file: /tmp/RtmpFlVxl1/eurostat/tgs00026_raw_code_FF.rds
-# Download geospatial data from CISGO
-geodata <- get_eurostat_geospatial(output_class = "sf", resolution = "60")
## [1] "Download geospatial data from GISCO"
+geodata <- get_eurostat_geospatial(output_class = "sf", resolution = "60")
##
## COPYRIGHT NOTICE
##
@@ -980,7 +985,7 @@
##
## # --------------------------
##
-# merge with attribute data with geodata
+# Merge with attribute data with geodata
map_data <- inner_join(geodata, euro_sf2)
## Joining, by = "geo"
# plot map
@@ -1007,9 +1012,9 @@
dplyr::filter(time == 2014, nchar(geo) == 4) %>%
# classifying the values the variable
dplyr::mutate(cat = cut_to_classes(values))
-## Reading cache file /tmp/RtmpFlVxl1/eurostat/tgs00026_raw_code_FF.rds
-## Table tgs00026 read from cache file: /tmp/RtmpFlVxl1/eurostat/tgs00026_raw_code_FF.rds
-# Download geospatial data from CISGO
+## Reading cache file /tmp/Rtmpabr3HV/eurostat/tgs00026_raw_code_FF.rds
+## Table tgs00026 read from cache file: /tmp/Rtmpabr3HV/eurostat/tgs00026_raw_code_FF.rds
+# Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "spdf", resolution = "10", nuts_level = 2)
##
## COPYRIGHT NOTICE
@@ -1038,7 +1043,7 @@
## information regarding their licence agreements.
##
## No encoding supplied: defaulting to UTF-8.
-## SpatialPolygonDataFrame at resolution 1: 10 cached at: /tmp/RtmpFlVxl1/eurostat/spdf102.RData
+## SpatialPolygonDataFrame at resolution 1: 10 cached at: /tmp/Rtmpabr3HV/eurostat/spdf102.RData
##
## # --------------------------
## HEADS UP!!
@@ -1075,9 +1080,9 @@
dplyr::filter(time == 2014, nchar(geo) == 4) %>%
# classifying the values the variable
dplyr::mutate(cat = cut_to_classes(values))
-## Reading cache file /tmp/RtmpFlVxl1/eurostat/tgs00026_raw_code_FF.rds
-## Table tgs00026 read from cache file: /tmp/RtmpFlVxl1/eurostat/tgs00026_raw_code_FF.rds
-# Download geospatial data from CISGO
+## Reading cache file /tmp/Rtmpabr3HV/eurostat/tgs00026_raw_code_FF.rds
+## Table tgs00026 read from cache file: /tmp/Rtmpabr3HV/eurostat/tgs00026_raw_code_FF.rds
+# Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "df", resolution = "60", nuts_level = "2")
##
## COPYRIGHT NOTICE
diff --git a/docs/articles/publications.html b/docs/articles/publications.html
index 0ab93fb4..e93b9f86 100755
--- a/docs/articles/publications.html
+++ b/docs/articles/publications.html
@@ -83,7 +83,7 @@
Publications using the eurostat R package
- 2018-05-19
+ 2018-05-20
publications.Rmd
diff --git a/vignettes/eurostat_tutorial.Rmd b/vignettes/eurostat_tutorial.Rmd
index ae110a2c..d08557cd 100755
--- a/vignettes/eurostat_tutorial.Rmd
+++ b/vignettes/eurostat_tutorial.Rmd
@@ -300,7 +300,7 @@ sp_data <- eurostat::get_eurostat("tgs00026", time_format = "raw", stringsAsFact
# categorise
dplyr::mutate(income = cut_to_classes(values, n = 5))
-# Download geospatial data from CISGO
+# Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "sf", resolution = "60")
# merge with attribute data with geodata
@@ -344,18 +344,22 @@ library(dplyr)
library(sf)
library(RColorBrewer)
-# Downloading and manipulating the tabular data
-euro_sf2 <- eurostat::get_eurostat("tgs00026", time_format = "raw", stringsAsFactors = FALSE) %>%
- # subsetting to year 2014 and NUTS-3 level
- dplyr::filter(time == 2014, grepl("PL",geo)) %>%
+# Downloading and manipulating the tabular data
+print("Let us focus on year 2014 and NUTS-3 level")
+euro_sf2 <- get_eurostat("tgs00026", time_format = "raw",
+ stringsAsFactors = FALSE,
+ filter = list(time = "2014")) %>%
+
+ # Subset to NUTS-3 level
+ dplyr::filter(grepl("PL",geo)) %>%
# label the single geo column
mutate(label = paste0(label_eurostat(.)[["geo"]], "\n", values, "€"),
income = cut_to_classes(values))
-# Download geospatial data from CISGO
+print("Download geospatial data from GISCO")
geodata <- get_eurostat_geospatial(output_class = "sf", resolution = "60")
-# merge with attribute data with geodata
+# Merge with attribute data with geodata
map_data <- inner_join(geodata, euro_sf2)
# plot map
@@ -383,7 +387,7 @@ dat <- get_eurostat("tgs00026", time_format = "raw", stringsAsFactors = FALSE) %
# classifying the values the variable
dplyr::mutate(cat = cut_to_classes(values))
-# Download geospatial data from CISGO
+# Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "spdf", resolution = "10", nuts_level = 2)
# merge with attribute data with geodata
@@ -410,7 +414,7 @@ dat <- get_eurostat("tgs00026", time_format = "raw", stringsAsFactors = FALSE) %
# classifying the values the variable
dplyr::mutate(cat = cut_to_classes(values))
-# Download geospatial data from CISGO
+# Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "df", resolution = "60", nuts_level = "2")
# merge with attribute data with geodata
diff --git a/vignettes/eurostat_tutorial.md b/vignettes/eurostat_tutorial.md
index 75190307..b88060c7 100755
--- a/vignettes/eurostat_tutorial.md
+++ b/vignettes/eurostat_tutorial.md
@@ -840,9 +840,9 @@ The mapping examples below use
# categorise
dplyr::mutate(income = cut_to_classes(values, n = 5))
- ## Table tgs00026 cached at /tmp/Rtmpn75WwS/eurostat/tgs00026_raw_code_FF.rds
+ ## Table tgs00026 cached at /tmp/Rtmpav96gu/eurostat/tgs00026_raw_code_FF.rds
- # Download geospatial data from CISGO
+ # Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "sf", resolution = "60")
##
@@ -927,19 +927,25 @@ Interactive maps can be generated as well
library(sf)
library(RColorBrewer)
- # Downloading and manipulating the tabular data
- euro_sf2 <- eurostat::get_eurostat("tgs00026", time_format = "raw", stringsAsFactors = FALSE) %>%
- # subsetting to year 2014 and NUTS-3 level
- dplyr::filter(time == 2014, grepl("PL",geo)) %>%
+ # Downloading and manipulating the tabular data
+ print("Let us focus on year 2014 and NUTS-3 level")
+
+ ## [1] "Let us focus on year 2014 and NUTS-3 level"
+
+ euro_sf2 <- get_eurostat("tgs00026", time_format = "raw",
+ stringsAsFactors = FALSE,
+ filter = list(time = "2014")) %>%
+
+ # Subset to NUTS-3 level
+ dplyr::filter(grepl("PL",geo)) %>%
# label the single geo column
mutate(label = paste0(label_eurostat(.)[["geo"]], "\n", values, "€"),
income = cut_to_classes(values))
- ## Reading cache file /tmp/Rtmpn75WwS/eurostat/tgs00026_raw_code_FF.rds
+ print("Download geospatial data from GISCO")
- ## Table tgs00026 read from cache file: /tmp/Rtmpn75WwS/eurostat/tgs00026_raw_code_FF.rds
+ ## [1] "Download geospatial data from GISCO"
- # Download geospatial data from CISGO
geodata <- get_eurostat_geospatial(output_class = "sf", resolution = "60")
##
@@ -986,7 +992,7 @@ Interactive maps can be generated as well
## # --------------------------
##
- # merge with attribute data with geodata
+ # Merge with attribute data with geodata
map_data <- inner_join(geodata, euro_sf2)
## Joining, by = "geo"
@@ -1016,11 +1022,11 @@ Interactive maps can be generated as well
# classifying the values the variable
dplyr::mutate(cat = cut_to_classes(values))
- ## Reading cache file /tmp/Rtmpn75WwS/eurostat/tgs00026_raw_code_FF.rds
+ ## Reading cache file /tmp/Rtmpav96gu/eurostat/tgs00026_raw_code_FF.rds
- ## Table tgs00026 read from cache file: /tmp/Rtmpn75WwS/eurostat/tgs00026_raw_code_FF.rds
+ ## Table tgs00026 read from cache file: /tmp/Rtmpav96gu/eurostat/tgs00026_raw_code_FF.rds
- # Download geospatial data from CISGO
+ # Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "spdf", resolution = "10", nuts_level = 2)
##
@@ -1052,7 +1058,7 @@ Interactive maps can be generated as well
## No encoding supplied: defaulting to UTF-8.
- ## SpatialPolygonDataFrame at resolution 1: 10 cached at: /tmp/Rtmpn75WwS/eurostat/spdf102.RData
+ ## SpatialPolygonDataFrame at resolution 1: 10 cached at: /tmp/Rtmpav96gu/eurostat/spdf102.RData
##
## # --------------------------
@@ -1097,11 +1103,11 @@ data as `data.frame` with `output_class` argument set as `df`.
# classifying the values the variable
dplyr::mutate(cat = cut_to_classes(values))
- ## Reading cache file /tmp/Rtmpn75WwS/eurostat/tgs00026_raw_code_FF.rds
+ ## Reading cache file /tmp/Rtmpav96gu/eurostat/tgs00026_raw_code_FF.rds
- ## Table tgs00026 read from cache file: /tmp/Rtmpn75WwS/eurostat/tgs00026_raw_code_FF.rds
+ ## Table tgs00026 read from cache file: /tmp/Rtmpav96gu/eurostat/tgs00026_raw_code_FF.rds
- # Download geospatial data from CISGO
+ # Download geospatial data from GISCO
geodata <- get_eurostat_geospatial(output_class = "df", resolution = "60", nuts_level = "2")
##
diff --git a/vignettes/fig/maps2-1.pdf b/vignettes/fig/maps2-1.pdf
index 4c466388..026c75ec 100644
Binary files a/vignettes/fig/maps2-1.pdf and b/vignettes/fig/maps2-1.pdf differ
diff --git a/vignettes/fig/plotGallery-1.pdf b/vignettes/fig/plotGallery-1.pdf
index b2222ed6..564726db 100644
Binary files a/vignettes/fig/plotGallery-1.pdf and b/vignettes/fig/plotGallery-1.pdf differ
diff --git a/vignettes/fig/trains_plot-1.pdf b/vignettes/fig/trains_plot-1.pdf
index f6324e12..2b13f871 100644
Binary files a/vignettes/fig/trains_plot-1.pdf and b/vignettes/fig/trains_plot-1.pdf differ