Skip to content

Instantly share code, notes, and snippets.

@jjesusfilho
Last active October 24, 2017 07:38
Show Gist options
  • Save jjesusfilho/53cbc4f119ed765556ab7d68de1c704e to your computer and use it in GitHub Desktop.
Save jjesusfilho/53cbc4f119ed765556ab7d68de1c704e to your computer and use it in GitHub Desktop.
Retorna o logradouro e o latlong com base no cep
library(httr)
library(stringr)
library(purrr)
library(magrittr)
library(ggmap)
via_cep<-function(cep,latlong=TRUE){
cep %<>%stringr::str_replace("\\D","") %>%
stringr::str_pad(8,side="left",pad="0") %>%
as.character()
df<-cep %>%
purrr::map_dfr(~{
paste0("https://viacep.com.br/ws/",.x,"/json/") %>%
httr::GET() %>%
httr::content()
})
df2<-df %>%
pmap_dfr(~{
.x %>%
t() %>%
toString() %>%
ggmap::geocode()
})
df<-cbind(df,df2)
df
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment