Hbrandi
Hbrandi

Reputation: 171

ggmap::mapdist gives Internal error in `vec_slice_impl()`: Unexpected `NULL`

Can someone help me understand why I get the following error for the mapdist function for ggmap package in R?

I am trying to get the minutes it takes to travel between two zip codes in Denmark. For some reason, there are some combinations that will work while others will not. For those that do not work, I tried searching for the zipcode on google maps to ensure that it does exist and that google knows about it - and here it will find it without any problems.

The console will give me the following output, when I run it:

mapdist(from = c("1050, Denmark"), to = c("2200, Denmark"))$minutes
Internal error in `vec_slice_impl()`: Unexpected `NULL`
Error: Internal error in `vec_slice_impl()`: Unexpected `NULL`.
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Internal error in `vec_slice_impl()`: Unexpected `NULL`.
Backtrace:
     x
  1. \-ggmap::mapdist(from = c("1050, Denmark"), to = c("2200, Denmark"))
  2.   \-`%>%`(...)
  3.     +-base::withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
  4.     \-base::eval(quote(`_fseq`(`_lhs`)), env, env)
  5.       \-base::eval(quote(`_fseq`(`_lhs`)), env, env)
  6.         \-ggmap:::`_fseq`(`_lhs`)
  7.           \-magrittr::freduce(value, `_function_list`)
  8.             \-function_list[[i]](value)
  9.               \-dplyr::bind_rows(.)
 10.                 \-vctrs::vec_rbind(!!!dots, .names_to = .id)
 11.                   \-(function () ...

Example of the same, where it works as you would expect it to

mapdist(from = c("2970, Denmark"), to = c("2200, Denmark"))$minutes
Source : https://maps.googleapis.com/maps/api/distancematrix/json?origins=2970,+Denmark&destinations=2200,+Denmark&key=xxx&mode=driving
[1] 23.46667

Upvotes: 1

Views: 363

Answers (1)

Santiago I. Hurtado
Santiago I. Hurtado

Reputation: 1123

That is beacause in googlemap you have to add a letter to certain zipcodes in Denmark. This will work:

mapdist(from = c("1050 K, Denmark"), to = c("2200, Denmark"))$minutes

It gives to me 12.0333

Add a "k" to all zipcodes in 1000-1499; a "V" for 1500-1799; and a "C" for 1800-1999.

Upvotes: 1

Related Questions