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

Chores/prep cran siane #6

Merged
merged 7 commits into from
May 6, 2018
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
11 changes: 9 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -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

21 changes: 11 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",role = c("aut","cre")),
person("Nuno", "Carvalho", role = c("aut"),
email = "[email protected]", role = c("aut")),
person("Nuno", "Carvalho", role = c("cre", "aut"),
email = "[email protected]"))
Author: Carlos J. Gil Bellosta[aut, cre]
Nuno Carvalho[aut]
Maintainer: Nuno Carvalho <[email protected]>
Depends: RColorBrewer, classInt, maptools, plyr, raster, rgdal, sp
RoxygenNote: 6.0.1
Suggests: knitr,
rmarkdown
Expand Down
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2017-2018
COPYRIGHT HOLDER: Carlos J. Gil Bellosta, Nuno Carvalho
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 0 additions & 7 deletions R/brks_color.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/get_dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions R/siane_map.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#' @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

#' @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}


Expand Down Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions R/siane_merge.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#' @title Merges data and maps
#'
#'@importFrom plyr join
#' @description This is a function that binds data to polygons
#'

#' @examples
#' \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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/stop_advices.R
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion man/siane_map.Rd

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

6 changes: 4 additions & 2 deletions man/siane_merge.Rd

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