joelgombin / banR

R client for the BAN API
http://joelgombin.github.io/banR/
GNU General Public License v3.0
28 stars 10 forks source link

'code_postal' argument unused in 'geocode_tbl' function ? #17

Closed mtmx closed 6 years ago

mtmx commented 6 years ago

Hello Joel, thanks for this great job. For some reason it seems the geocode_tbl function used with only one argument (adresse as a concatenation of street, zip code and city) sends back more accurate results than when it's used with multiple argument (adresse = street, code_postal = zip code).

Example :

library(tidyverse)
df <- tribble(
  ~ num_voie, ~ cp,  ~ ville,  
  "1 Rue Gaspard Monge", "22307", "Lannion Cedex",
  "Square Edouard Herriot", "85400", "Lucon")

library(banR)
  geocode_tbl(tbl = df , adresse = num_voie, code_postal = cp) %>%
  glimpse() %>% View()

  geocode_tbl(tbl = df %>% mutate(adr = paste0(num_voie,", ", cp, " ",ville)), adresse = adr) %>%
  glimpse() %>% View()

I guess 'code_postal' argument remains unused, so any adress who matches will be returned, even if it's not in the right city. Or did I miss something ?

pachevalier commented 6 years ago

Ok, I confirm that there is a problem : https://gist.github.com/pachevalier/399f50ef036ba88cc2d8325ead6e5a94.

I'll investigate.

pachevalier commented 6 years ago

Ok, the name of the postcode variable in the geocode_tbl(à) function was simply wrong (postalcode instead of postcode).

Pull request #18 should correct this.

Thanks for the bug report.

pachevalier commented 6 years ago

@mtmx you can test it using :

devtools::install_github("joelgombin/banR", ref = "pac-codepostal")

joelgombin commented 6 years ago

merged in master. @mtmx can you confirm the issue is closed?

mtmx commented 6 years ago

Thanks for your answer. 'geocode_tbl' function with a _codepostal argument sends back NA values for the first adress :

geocode_tbl(tbl = df , adresse = num_voie, code_postal = cp) %>%
  glimpse() %>% View()

whereas 'geocode_tbl' function without a _codepostal argument sends back the right answer :

  geocode_tbl(tbl = df %>% mutate(adr = paste0(num_voie,", ", cp, " ",ville)), adresse = adr) %>%
  glimpse() %>% View()

so I guess there's still something wrong.

pachevalier commented 6 years ago

Ok, je regarde

pachevalier commented 6 years ago

@mtmx l'erreur vient des données en entrées plutôt que du code. Le code postal de Lannion n'est pas 22307 mais 22300 ou 22303 Voir Wikipédia.

C'est plus un problème de prise en compte des cedex dans la Base adresse nationale.

Le code ci-dessous marche très bien ;

library(tidyverse)
library(banR)
df <- tribble(
  ~ num_voie, ~ cp,  ~ ville,  
  "1 Rue Gaspard Monge", "22300", "Lannion Cedex",
  "Square Edouard Herriot", "85400", "Lucon")
geocode_tbl(tbl = df , adresse = num_voie, code_postal = cp) %>%
  glimpse() 
geocode_tbl(tbl = df %>% mutate(adr = paste0(num_voie,", ", cp, " ",ville)), adresse = adr) %>%
  glimpse() 
mtmx commented 6 years ago

OK merci pour les infos. Pour la fonction geocode_tbl, j'en resterai donc à l'utilisation d'un champ concaténant adresse/CP/ville puisque le résultat sera meilleur qu'avec les paramètres adresse et CP envoyés séparément.