问题描述
有人可以帮助我理解为什么我在R中的ggmap软件包的mapdist函数中遇到以下错误吗?
我正在尝试获取在丹麦的两个邮政编码之间旅行所需的时间。由于某些原因,有些组合会起作用,而其他组合则不会。对于不起作用的用户,我尝试在google地图上搜索邮政编码,以确保它确实存在并且google知道它-在这里它将找到它而没有任何问题。
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"))
2. \-`%>%`(...)
3. +-base::withVisible(eval(quote(`_fseq`(`_lhs`)),env,env))
4. \-base::eval(quote(`_fseq`(`_lhs`)),env)
5. \-base::eval(quote(`_fseq`(`_lhs`)),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 () ...
相同的示例,它在您期望的地方起作用
mapdist(from = c("2970,Denmark"))$minutes
Source : https://maps.googleapis.com/maps/api/distancematrix/json?origins=2970,+Denmark&destinations=2200,+Denmark&key=xxx&mode=driving
[1] 23.46667
解决方法
这是因为在googlemap中,您必须向丹麦的某些邮政编码添加字母。这将起作用:
mapdist(from = c("1050 K,Denmark"),to = c("2200,Denmark"))$minutes
它给了我12.0333
在1000-1499年的所有邮政编码中添加“ k”; 1500至1799年的“ V”;和“ C”代表1800-1999。