diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..e50130e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,9 @@ -^.*\.Rproj$ -^\.Rproj\.user$ +^.*\.Rproj$ # Automatically added by RStudio, +^\.Rproj\.user$ # used for temporary files. +^README.md$ # An Rmarkdown file used to generate README.md +Images +.git +.gitignore +RData +Siane.Rproj + diff --git a/DESCRIPTION b/DESCRIPTION index b8a5cb8..15ec6a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,19 +1,20 @@ Package: Siane -Title: Siane +Title: Explore the Spanish INE Data using this Geographic Tool Version: 0.1 -Description: Statistic polygon plots of INE data -Depends: R (>= 3.3.1) -License: MIT +Description: A tool that assists the user in two tasks: the map reading process and the + data representation process. The reading process is leveraged with functions that allow + the user to find maps in the Siane repository easily, i.e. searching by map year or + administrative level. The other main functionality is to bind numerical data to polygons. + This package is only compatible with the spanish IGN(National Institute of Geography) maps + and the INE(National Institute of Statistics) data. +Imports: plyr, raster, rgdal, sp, methods, utils +License: MIT + file LICENSE Encoding: UTF-8 LazyData: true Authors@R: c(person("Carlos J. Gil Bellosta", - email = "cgb@datanalytics.com",role = c("aut","cre")), - person("Nuno", "Carvalho", role = c("aut"), + email = "cgb@datanalytics.com", role = c("aut")), + person("Nuno", "Carvalho", role = c("cre", "aut"), email = "nunocarvalhodossantos@gmail.com")) -Author: Carlos J. Gil Bellosta[aut, cre] - Nuno Carvalho[aut] -Maintainer: Nuno Carvalho -Depends: RColorBrewer, classInt, maptools, plyr, raster, rgdal, sp RoxygenNote: 6.0.1 Suggests: knitr, rmarkdown diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b462b15 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2017-2018 +COPYRIGHT HOLDER: Carlos J. Gil Bellosta, Nuno Carvalho diff --git a/NAMESPACE b/NAMESPACE index e5494ab..1aa6d55 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,3 +4,10 @@ export(register_siane) export(siane_map) export(siane_merge) import("rgdal") +importFrom(methods,as) +importFrom(plyr,join) +importFrom(raster,bind) +importFrom(raster,extent) +importFrom(raster,shift) +importFrom(sp,"proj4string<-") +importFrom(sp,proj4string) diff --git a/R/brks_color.R b/R/brks_color.R deleted file mode 100644 index 8ec6dcd..0000000 --- a/R/brks_color.R +++ /dev/null @@ -1,7 +0,0 @@ - -brks_color <- function(n,pallete_colour, values_ine, style){ - brks <- classIntervals(values_ine, n = n, style = style) - brks <- brks$brks - - return(brks) -} diff --git a/R/get_dir.R b/R/get_dir.R index 35348b6..b910017 100644 --- a/R/get_dir.R +++ b/R/get_dir.R @@ -19,7 +19,7 @@ get_dir <- function(base_path, dirs_path,last_path, year){ folder_years <- sapply(dirs_path, - function(x) tail(strsplit(x = x,split = "/")[[1]],1)) # If the user introduces a year we try to search for the newest map until that year + function(x) utils::tail(strsplit(x = x,split = "/")[[1]],1)) # If the user introduces a year we try to search for the newest map until that year folder_years_num <- sapply(folder_years, diff --git a/R/siane_map.R b/R/siane_map.R index 5a64410..da51928 100644 --- a/R/siane_map.R +++ b/R/siane_map.R @@ -1,4 +1,7 @@ -#' @import "rgdal" +#' @import "rgdal" +#'@importFrom raster shift extent bind +#'@importFrom sp proj4string proj4string<- +#'@importFrom methods as #'@title Loads a spanish map #' #' @description A function that returns a S4 object(map) of a Spain specific map @@ -6,7 +9,7 @@ #' @examples #' \dontrun{ #' obj <- register_siane("/home/ncarvalho/Downloads/") # Registering a sample of Siane -#' shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE, peninsula = "close") # Loading the municipality's map of Spain +#' shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE, peninsula = "close") #' plot(shp) # Plot the map} @@ -64,7 +67,7 @@ siane_map <- function(obj, canarias, year, level, scale, peninsula){ shp_total <- bind(shp_peninsula, shp_canarias_shifted) - rectangle <- as(raster::extent(-0.5, 5, 11.6, 9), "SpatialPolygons") + rectangle <- as(extent(-0.5, 5, 9, 11.6), "SpatialPolygons") proj4string(rectangle) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" shif_rect <- shift(rectangle, y = 26) diff --git a/R/siane_merge.R b/R/siane_merge.R index 3c60f48..ebad679 100644 --- a/R/siane_merge.R +++ b/R/siane_merge.R @@ -1,5 +1,5 @@ #' @title Merges data and maps -#' +#'@importFrom plyr join #' @description This is a function that binds data to polygons #' @@ -7,9 +7,11 @@ #' \dontrun{ #' library(pxR) #' obj <- register_siane("/home/ncarvalho/Downloads/") -#' shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE) # Loading the municipality's map of Spain +#' # Loading the municipality's map of Spain +#' shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE) #' plot(shp) # Plot the map -#' df <- as.data.frame(read.px("/home/ncarvalho/Downloads/2879.px"))# Get this file in INE's website. Check the README to learn how to do it. +#' # Get this file in INE's website. Check the README to learn how to do it. +#' df <- as.data.frame(read.px("/home/ncarvalho/Downloads/2879.px")) #' by <- "codes" #' df[[by]] <- sapply(df$Municipios,function(x) strsplit(x = as.character(x), split = " ")[[1]][1]) #' year <- 2016 @@ -52,8 +54,9 @@ siane_merge <- function(shp, df, by, level, value){ stop_advices(df, by, value) # Stop sentences for column names: Values column and codes column. - shp_code <- shp_code(level) # The shape file column that contains the code depends on the level. This function returns the code's shp column name - + # The shape file column that contains the code depends on the level. + #This function returns the code's shp column name + shp_code <- shp_code(level) name_filter <- names(df) == by # names(df)[name_filter] <- shp_code # Renaming the column to make the join diff --git a/R/stop_advices.R b/R/stop_advices.R index ed72a08..9e59999 100644 --- a/R/stop_advices.R +++ b/R/stop_advices.R @@ -1,5 +1,5 @@ -stop_advices <- function(df,by,name){ +stop_advices <- function(df, by, value){ if((by %in% names(df)) == FALSE){ # Checking if the ID's column is in the dataframe stop(paste0("The column ", by, " is not in the data frame. Try to run names(df) to check the data frame column names")) diff --git a/README.md b/README.md index 9c2e657..645142a 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Now we are ready to go through the code. ``` library(devtools) -install_github("Nuniemsis/Siane") +install_github("rOpenSpain/Siane") library(pxR) # install.packages("pxR") library(Siane) library(RColorBrewer) diff --git a/man/siane_map.Rd b/man/siane_map.Rd index 39cf64f..a5d779b 100644 --- a/man/siane_map.Rd +++ b/man/siane_map.Rd @@ -38,6 +38,6 @@ The default value for the municipalities maps is \code{scale <- "3m"} . The defa \examples{ \dontrun{ obj <- register_siane("/home/ncarvalho/Downloads/") # Registering a sample of Siane -shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE, peninsula = "close") # Loading the municipality's map of Spain +shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE, peninsula = "close") plot(shp) # Plot the map} } diff --git a/man/siane_merge.Rd b/man/siane_merge.Rd index 9e33cdb..7947f46 100644 --- a/man/siane_merge.Rd +++ b/man/siane_merge.Rd @@ -39,9 +39,11 @@ There will be as many missing territories as missing codes in the dataframe. \cr \dontrun{ library(pxR) obj <- register_siane("/home/ncarvalho/Downloads/") -shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE) # Loading the municipality's map of Spain +# Loading the municipality's map of Spain +shp <- siane_map(obj = obj, level = "Municipios", canarias = FALSE) plot(shp) # Plot the map -df <- as.data.frame(read.px("/home/ncarvalho/Downloads/2879.px"))# Get this file in INE's website. Check the README to learn how to do it. +# Get this file in INE's website. Check the README to learn how to do it. +df <- as.data.frame(read.px("/home/ncarvalho/Downloads/2879.px")) by <- "codes" df[[by]] <- sapply(df$Municipios,function(x) strsplit(x = as.character(x), split = " ")[[1]][1]) year <- 2016