Giter VIP home page Giter VIP logo

Comments (3)

erzk avatar erzk commented on June 18, 2024

Thanks for spotting this issue. I will work on it over the weekend.
Feel free to send a PR if you managed to fix it yourself.

from postcodesior.

erzk avatar erzk commented on June 18, 2024

Are you using CRAN or GitHub version?
There are still some changes that haven't been pushed to CRAN so the dev (GitHub) version is the latest.
I don't get the error that you mentioned when running PostcodesioR::postcode_lookup("IM26BG") This line works for me as expected using the dev version.
Was that the only postcode that caused errors? Did you hit the query limit (postcodes.io limits the number of calls)?

from postcodesior.

MikeJohnPage avatar MikeJohnPage commented on June 18, 2024

In response to your questions:

  • I was using CRAN version (0.1.1)
  • Yes, it was the only postcode that was throwing an error, out of 257.
  • No, I wasn't hitting the query limit, I used map functions from the {purrr} package to iterate over a vector of postcodes one-by-one.

Solution with CRAN version

In case you are interested I solved the problem by using a combination of functions from {purrr} to ignore errors:

# Load libraries
library(tidyverse)
library(PostcodesioR)

# Create vector of postcodes
postcodes <- c("TEST123", "TEST456", "TEST789")

# Geocoding function to check if postcode is valid, and if so, return lat/lng,
# else silently ignore
geocode <- function(postcode){
  if(postcode_validation(postcode)){
    p <- postcode_lookup(postcode)
    tibble(postcode = postcode,
           latitude = purrr::pluck(p, "latitude"),
           longitude = purrr::pluck(p, "longitude"))
  }
}

# Handle errors safely
safe_geo <- safely(geocode)

# Return lat/lng coords
coords <- map(postcodes, safe_geo) %>% 
  transpose() %>% 
  use_series("result") %>% 
  bind_rows()

Dev version

I updated to the GitHub dev version and indeed it no longer throws an error for the same postcode. Thanks for the update 👍

from postcodesior.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.