-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Myles McDonnell
committed
Dec 28, 2018
0 parents
commit 5ae0f02
Showing
39 changed files
with
584 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
^README\.Rmd$ | ||
^LICENSE\.md$ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cursorPosition" : "33,0", | ||
"scrollLine" : "22" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cursorPosition" : "10,0", | ||
"scrollLine" : "0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cursorPosition" : "17,1", | ||
"scrollLine" : "3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cursorPosition" : "10,19", | ||
"scrollLine" : "0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cursorPosition" : "41,0", | ||
"scrollLine" : "25" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cursorPosition" : "60,32", | ||
"scrollLine" : "51" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
~%2Fsimplefeaturesbr%2FDESCRIPTION="50FD47BD" | ||
~%2Fsimplefeaturesbr%2FR%2Fbr_municipalities.R="78D443E9" | ||
~%2Fsimplefeaturesbr%2FR%2Fhello.R="6861775A" | ||
~%2Fsimplefeaturesbr%2FR%2Fselect.R="30CB432B" | ||
~%2Fsimplefeaturesbr%2FR%2Fsp.R="95357B42" | ||
~%2Fsimplefeaturesbr%2FREADME.Rmd="E6F5C04A" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"collab_server" : "", | ||
"contents" : "", | ||
"created" : 1546018345605.000, | ||
"dirty" : false, | ||
"encoding" : "UTF-8", | ||
"folds" : "", | ||
"hash" : "29812514", | ||
"id" : "123366F1", | ||
"lastKnownWriteTime" : 1546018474, | ||
"last_content_update" : 1546018474302, | ||
"path" : "~/simplefeaturesbr/R/br_municipalities.R", | ||
"project_path" : "R/br_municipalities.R", | ||
"properties" : { | ||
"cursorPosition" : "10,19", | ||
"scrollLine" : "0" | ||
}, | ||
"read_only" : false, | ||
"read_only_alternatives" : [ | ||
], | ||
"relative_order" : 3, | ||
"source_on_save" : false, | ||
"source_window" : "", | ||
"type" : "r_source" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#' A Simple Features Dataframe of Brazilian states and municipalities. | ||
#' | ||
#' \itemize{ | ||
#' \item name \code{character}. Full name of Brazilian municpality. | ||
#' \item state \code{character}. Acronym of Brazilian state. | ||
#' \item ibge_code \code{character}. IBGE code of municipality. | ||
#' \item geometry \code{character}. Simple features geometry. | ||
#' } | ||
#' | ||
#' @format A data frame with 5564 rows and 4 variables | ||
"br_municipalities" | ||
#> [1] "br_municipalities" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' @importFrom dplyr filter | ||
#' @importFrom congressbr UF | ||
|
||
#' @export | ||
UF <- function() congressbr::UF | ||
|
||
#' @param state Two-letter abbreviation of Brazilian state name. Use \code{UF()} for | ||
#' a list. | ||
#' @export | ||
select_state <- function(state) { | ||
|
||
uf <- c("AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", | ||
"GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", | ||
"PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", | ||
"SP", "SE", "TO") | ||
|
||
if(!state %in% uf) stop("State not found. Try `UF()` for a list of possibilities.") | ||
|
||
data("br_municipalities") | ||
|
||
st <- rlang::enquo(state) | ||
|
||
br_state <- br_municipalities %>% | ||
dplyr::filter(state == !! st) | ||
|
||
return(br_state) | ||
|
||
} | ||
|
||
#' @param municipality . Name of municipality. For a dataframe of these, plus their | ||
#' state and ID, use \code{data("ibge")}. | ||
#' @export | ||
select_municipality <- function(municipality){ | ||
mun <- enquo(municipality) | ||
|
||
br_mun <- br_municipalities %>% | ||
dplyr::filter(name == !! mun) | ||
|
||
return(br_mun) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"collab_server" : "", | ||
"contents" : "", | ||
"created" : 1546018609843.000, | ||
"dirty" : false, | ||
"encoding" : "UTF-8", | ||
"folds" : "", | ||
"hash" : "0", | ||
"id" : "54DB6F21", | ||
"lastKnownWriteTime" : 1546019413, | ||
"last_content_update" : 1546019413805, | ||
"path" : "~/simplefeaturesbr/README.Rmd", | ||
"project_path" : "README.Rmd", | ||
"properties" : { | ||
"cursorPosition" : "60,32", | ||
"scrollLine" : "51" | ||
}, | ||
"read_only" : false, | ||
"read_only_alternatives" : [ | ||
], | ||
"relative_order" : 4, | ||
"source_on_save" : false, | ||
"source_window" : "", | ||
"type" : "r_markdown" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
output: github_document | ||
--- | ||
|
||
<!-- README.md is generated from README.Rmd. Please edit that file --> | ||
|
||
```{r setup, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>", | ||
fig.path = "man/figures/README-", | ||
out.width = "100%" | ||
) | ||
``` | ||
# simplefeaturesbr | ||
|
||
The goal of simplefeaturesbr is to make [Simple Features](https://en.wikipedia.org/wiki/Simple_Features) tidy data frames of Brazilian states and municipalities easily available in R. | ||
|
||
## Installation | ||
|
||
You can install simplefeaturesbr with: | ||
|
||
``` r | ||
remotes::install_github("BrazilianPublicData/simplefeaturesbr") | ||
``` | ||
|
||
## Usage | ||
|
||
simplefeaturesbr has a main dataset, `br_municipalities`, and some simple convenience functions to select from this dataset. You can access the data with: | ||
|
||
```{r} | ||
data("br_municipalities") | ||
``` | ||
|
||
It looks like this: | ||
|
||
```{r} | ||
head(br_municipalities) | ||
``` | ||
|
||
If you are interested in a specific state, use `select_state()`: | ||
```{r} | ||
select_state("SP") | ||
``` | ||
|
||
If you'd like to get data for a specific municipality, use `select_municipality()`: | ||
```{r} | ||
select_municipality("Sao Paulo") | ||
``` | ||
|
||
There are two other things to help you. If you can't remember which [IBGE](https://www.ibge.gov.br/en/home-eng.html) code (two-letter abbreviations of Brazilian states) you need, use `UF()` (copy of a simple function from [congressbr](https://github.com/BrazilianPublicData/congressbr)): | ||
|
||
```{r} | ||
UF() | ||
``` | ||
|
||
## Why? | ||
Simple features make _much_ smaller dataframes than spatial polygons. You can plot them easily with ggplot2's `geom_sf()`: | ||
|
||
```{r} | ||
library(dplyr); library(ggplot2) | ||
|
||
select_municipality("Rio de Janeiro") %>% ggplot() + geom_sf() | ||
``` | ||
|
||
Nice. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Hello, world! | ||
# | ||
# This is an example function named 'hello' | ||
# which prints 'Hello, world!'. | ||
# | ||
# You can learn more about package authoring with RStudio at: | ||
# | ||
# http:https://r-pkgs.had.co.nz/ | ||
# | ||
# Some useful keyboard shortcuts for package authoring: | ||
# | ||
# Install Package: 'Cmd + Shift + B' | ||
# Check Package: 'Cmd + Shift + E' | ||
# Test Package: 'Cmd + Shift + T' | ||
|
||
hello <- function() { | ||
print("Hello, world!") | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"collab_server" : "", | ||
"contents" : "", | ||
"created" : 1546018149342.000, | ||
"dirty" : false, | ||
"encoding" : "UTF-8", | ||
"folds" : "", | ||
"hash" : "0", | ||
"id" : "A87EEDD3", | ||
"lastKnownWriteTime" : 1546018576, | ||
"last_content_update" : 1546018576971, | ||
"path" : "~/simplefeaturesbr/R/select.R", | ||
"project_path" : "R/select.R", | ||
"properties" : { | ||
"cursorPosition" : "33,0", | ||
"scrollLine" : "22" | ||
}, | ||
"read_only" : false, | ||
"read_only_alternatives" : [ | ||
], | ||
"relative_order" : 2, | ||
"source_on_save" : false, | ||
"source_window" : "", | ||
"type" : "r_source" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' @importFrom dplyr filter | ||
#' @importFrom congressbr UF | ||
#' @title Print Brazilian State Abbreviations to the Console | ||
#' @export | ||
UF <- function() { | ||
uf <- c("AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", | ||
"GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", | ||
"PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", | ||
"SP", "SE", "TO") | ||
print(uf) | ||
} | ||
|
||
#' @title Load Simple Features DataFrame of a Brazilian State | ||
#' @param state Two-letter abbreviation of Brazilian state name. Use \code{UF()} for | ||
#' a list. | ||
#' @export | ||
select_state <- function(state) { | ||
|
||
uf <- c("AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", | ||
"GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", | ||
"PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", | ||
"SP", "SE", "TO") | ||
|
||
if(!state %in% uf) stop("State not found. Try `UF()` for a list of possibilities.") | ||
|
||
data("br_municipalities") | ||
|
||
st <- rlang::enquo(state) | ||
|
||
br_state <- br_municipalities %>% | ||
dplyr::filter(state == !! st) | ||
|
||
return(br_state) | ||
|
||
} | ||
|
||
#' @title Load Simple Features DataFrame of a Brazilian Municipality | ||
#' @param municipality Name of municipality. For a dataframe of these, plus their | ||
#' state and ID, use \code{data("ibge")}. | ||
#' @export | ||
select_municipality <- function(municipality){ | ||
mun <- enquo(municipality) | ||
|
||
br_mun <- br_municipalities %>% | ||
dplyr::filter(name == !! mun) | ||
|
||
return(br_mun) | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"collab_server" : "", | ||
"contents" : "", | ||
"created" : 1546002774058.000, | ||
"dirty" : false, | ||
"encoding" : "UTF-8", | ||
"folds" : "", | ||
"hash" : "0", | ||
"id" : "E98D93FC", | ||
"lastKnownWriteTime" : 1546018138, | ||
"last_content_update" : 1546018138, | ||
"path" : "~/simplefeaturesbr/DESCRIPTION", | ||
"project_path" : "DESCRIPTION", | ||
"properties" : { | ||
"cursorPosition" : "10,0", | ||
"scrollLine" : "0" | ||
}, | ||
"read_only" : false, | ||
"read_only_alternatives" : [ | ||
], | ||
"relative_order" : 1, | ||
"source_on_save" : false, | ||
"source_window" : "", | ||
"type" : "dcf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Package: simplefeaturesbr | ||
Type: Package | ||
Title: Simple Features Tidy Dataframes of Brazilian Municipalities in R | ||
Version: 0.1.0 | ||
Author: Robert Myles McDonnell | ||
Maintainer: Robert Myles McDonnell <[email protected]> | ||
Description: Makes Simple Features (sf) tidy dataframes of Brazilian municipalities easily available in R. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.1.1 |
Empty file.
1 change: 1 addition & 0 deletions
1
.Rproj.user/shared/notebooks/918C6F50-README/1/260DA0C72D5908F/chunks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"chunk_definitions":[],"doc_write_time":1546018616} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"chunk_definitions":[],"doc_write_time":1546018616} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/Users/robert/simplefeaturesbr/R/sp.R="87530BE1" | ||
/Users/robert/simplefeaturesbr/README.Rmd="918C6F50" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Package: simplefeaturesbr | ||
Type: Package | ||
Title: Simple Features Tidy Dataframes of Brazilian Municipalities in R | ||
Version: 0.1.0 | ||
Author: Robert Myles McDonnell | ||
Maintainer: Robert Myles McDonnell <[email protected]> | ||
Description: Makes Simple Features (sf) tidy dataframes of Brazilian municipalities easily available in R. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2018 | ||
COPYRIGHT HOLDER: Robert Myles McDonnell |
Oops, something went wrong.