-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
1f0520b
commit 87dd841
Showing
3 changed files
with
42 additions
and
2 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 |
---|---|---|
|
@@ -12,4 +12,3 @@ | |
.RData | ||
^_pkgdown\.yml$ | ||
^pkgdown$ | ||
^data_prep |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: censobr | ||
Title: Download Data from Brazil's Population Census | ||
Version: 0.3.2 | ||
Version: 0.3.29999 | ||
Authors@R: | ||
c(person(given="Rafael H. M.", family="Pereira", | ||
email="[email protected]", | ||
|
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 @@ | ||
#' Add geometry information of census tracts | ||
#' | ||
#' @param df An arrow `Dataset` passed from function above. | ||
#' @param year Numeric. Passed from function above. | ||
#' @param showProgress Logical. Passed from function above. | ||
#' | ||
#' @return An arrow `Dataset` with additional geometry variable. | ||
#' | ||
#' @keywords internal | ||
geometry <- function(df, | ||
year = parent.frame()$year, | ||
showProgress = parent.frame()$showProgress){ | ||
|
||
# df <- censobr::read_tracts(year = 2022, dataset = 'PessoaRenda') | ||
# df <- dplyr::collect(df) | ||
|
||
# download tracts geometry from geobr | ||
tracts_sf <- geobr::read_census_tract(code_tract = 'all', | ||
year = year, | ||
showProgress = showProgress) | ||
|
||
# hamonize col classes | ||
df <- dplyr::mutate(df, code_muni = as.numeric(code_muni), | ||
code_state = as.numeric(code_state)) | ||
|
||
if (year == 2010) { | ||
|
||
# determine key vars | ||
key_vars <- c("code_tract", "code_muni", "code_state") | ||
} | ||
|
||
# drop repeated vars | ||
all_common_vars <- names(df)[names(df) %in% names(tracts_sf)] | ||
vars_to_drop <- setdiff(all_common_vars, key_vars) | ||
tracts_sf <- dplyr::select(tracts_sf, -all_of(vars_to_drop)) | ||
|
||
# merge | ||
temp_sf <- dplyr::left_join(df, tracts_sf) | ||
|
||
return(temp_sf) | ||
} |