Skip to content

Commit

Permalink
Ready for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
antagomir committed May 20, 2018
1 parent 6d708f1 commit 4abc95d
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 54 deletions.
7 changes: 4 additions & 3 deletions R/get_eurostat_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions R/get_eurostat_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/articles/blogposts.html

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

2 changes: 1 addition & 1 deletion docs/articles/cheatsheet.html

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

45 changes: 25 additions & 20 deletions docs/articles/eurostat_tutorial.html

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

2 changes: 1 addition & 1 deletion docs/articles/publications.html

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

22 changes: 13 additions & 9 deletions vignettes/eurostat_tutorial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 4abc95d

Please sign in to comment.