google route optimizer

The best way to preface a question is with a reproducible example, called a reprex, so that we can better see where you're stuck. Not everyone has used the google route optimizer, but lots of peeps in the community can spot holes in the code.

Assuming you have an object with five pairs of point coordinates, the problem decomposes into two parts:

  1. What is the distance within your projection system between each pair of points i, j?
  2. What traversal of the points minimizes \sum\limits^j\limits_i of distances{_i}{_j}?

With the sf library, you can easily create a points object to contain i and j.

and the igraph library has functions to calculate traversal distances. For as few as five points, this should be fairly straightforward.