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

Avoid binding errors #162

Merged
merged 4 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions R/check_nuts2013.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

check_nuts2013 <- function (dat,
return_changed_regions = FALSE ) {

## For non-standard evaluation -------------------------------------
change <- geo <- code13 <- code16 <- NULL

data("regional_changes_2016")

unchanged_regions <- regional_changes_2016 %>%
filter ( change == 'unchanged')
Expand Down
10 changes: 9 additions & 1 deletion R/harmonize_geo_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' that cannot be brought to the current \code{'NUTS2016'} definition.
#' If not called before, the function will use the helper function
#' \code{\link{check_nuts2013}}
#' @importFrom dplyr left_join mutate filter rename
#' @importFrom dplyr left_join mutate filter rename full_join
#' @importFrom stringr str_sub
#' @examples
#' \dontrun{
Expand All @@ -29,6 +29,14 @@

harmonize_geo_code <- function ( dat ) {

## For non-standard evaluation -------------------------------------
change <- tmp <- geo <- nuts_level <- code13 <- code16 <- NULL
remaining_eu_data <- NULL


data("regional_changes_2016")
data("nuts_correspondence")

## Check if geo information is present ------------------------------
if (check_dat_input(dat)) {
stop ("There is no 'geo' column in the inserted data. This is an error.") }
Expand Down
15 changes: 8 additions & 7 deletions data-raw/nuts_coding.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ regions <- readxl::read_excel( tf,
TRUE ~ NA_character_))

nuts1_correspondence <- readxl::read_excel(
tf, sheet = 'Correspondence NUTS-1',
#file.path('data-raw', 'NUTS2013-NUTS2016.xlsx'),
#file.path('.', 'NUTS2013-NUTS2016.xlsx'),
file.path(tf),
Expand All @@ -38,10 +39,8 @@ nuts1_correspondence <- readxl::read_excel(
mutate_if ( is.factor, as.character ) %>%
mutate ( nuts_level = 1 )


nuts2_correspondence <- readxl::read_excel(
#file.path('data-raw', 'NUTS2013-NUTS2016.xlsx'),
file.path(tf),
nuts2_correspondence <- readxl::read_excel(
tf, sheet = 'Correspondence NUTS-2',
sheet = 'Correspondence NUTS-2',
skip = 0 , col_names = T) %>%
select ( 1:5 ) %>%
Expand All @@ -58,28 +57,30 @@ nuts_correspondence <- rbind (

nuts_2016_codes <- unique (regions$code16)

##In these cases, the code13 == code16
##In these cases, the code13 == code16 ------------------------------
unchanged_regions <- regions %>%
filter ( is.na(change)) %>%
fill ( nuts1_name ) %>%
fill ( nuts2_name ) %>%
select ( code13, code16, name, nuts_level, change ) %>%
mutate ( change = 'unchanged')

## In these cases code13 != code16
## In these cases code13 != code16 ----------------------------------
changed_regions <- regions %>%
filter ( !is.na(change)) %>%
fill ( nuts1_name ) %>%
fill ( nuts2_name ) %>%
select ( code13, code16, name, nuts_level, change )

## Regional changes
## Regional changes ------------------------------------------------

regional_changes_2016 <- rbind ( changed_regions, unchanged_regions )

discontinued_regions <- changed_regions %>%
filter ( change == "discontinued")


## ----------------------------------------------------------------
message("Save changed regions")
usethis::use_data(regional_changes_2016,
nuts_correspondence, overwrite = TRUE,
Expand Down