Skip to content

Commit

Permalink
🇧🇷
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Myles McDonnell committed Dec 28, 2018
0 parents commit 5ae0f02
Show file tree
Hide file tree
Showing 39 changed files with 584 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
^README\.Rmd$
^LICENSE\.md$
^.*\.Rproj$
^\.Rproj\.user$
4 changes: 4 additions & 0 deletions .Rproj.user/260DA0C7/sources/prop/30CB432B
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cursorPosition" : "33,0",
"scrollLine" : "22"
}
4 changes: 4 additions & 0 deletions .Rproj.user/260DA0C7/sources/prop/50FD47BD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cursorPosition" : "10,0",
"scrollLine" : "0"
}
4 changes: 4 additions & 0 deletions .Rproj.user/260DA0C7/sources/prop/6861775A
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cursorPosition" : "17,1",
"scrollLine" : "3"
}
4 changes: 4 additions & 0 deletions .Rproj.user/260DA0C7/sources/prop/78D443E9
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cursorPosition" : "10,19",
"scrollLine" : "0"
}
4 changes: 4 additions & 0 deletions .Rproj.user/260DA0C7/sources/prop/95357B42
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cursorPosition" : "41,0",
"scrollLine" : "25"
}
4 changes: 4 additions & 0 deletions .Rproj.user/260DA0C7/sources/prop/E6F5C04A
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cursorPosition" : "60,32",
"scrollLine" : "51"
}
6 changes: 6 additions & 0 deletions .Rproj.user/260DA0C7/sources/prop/INDEX
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"
25 changes: 25 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/123366F1
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"
}
12 changes: 12 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/123366F1-contents
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"
41 changes: 41 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/1F773467-contents
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)

}
25 changes: 25 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/54DB6F21
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"
}
66 changes: 66 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/54DB6F21-contents
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.
18 changes: 18 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/793EE85-contents
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.
25 changes: 25 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/A87EEDD3
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"
}
49 changes: 49 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/A87EEDD3-contents
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.
25 changes: 25 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/E98D93FC
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"
}
11 changes: 11 additions & 0 deletions .Rproj.user/260DA0C7/sources/s-2D5908F/E98D93FC-contents
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"chunk_definitions":[],"doc_write_time":1546018616}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"chunk_definitions":[],"doc_write_time":1546018616}
Empty file.
2 changes: 2 additions & 0 deletions .Rproj.user/shared/notebooks/paths
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"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
11 changes: 11 additions & 0 deletions DESCRIPTION
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
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2018
COPYRIGHT HOLDER: Robert Myles McDonnell
Loading

0 comments on commit 5ae0f02

Please sign in to comment.