Last active
          October 24, 2017 07:38 
        
      - 
      
 - 
        
Save jjesusfilho/53cbc4f119ed765556ab7d68de1c704e to your computer and use it in GitHub Desktop.  
    Retorna o logradouro e o latlong com base no cep 
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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