【发布时间】:2020-10-16 09:52:32
【问题描述】:
谁能帮我理解为什么我在 R 中为 ggmap 包的 mapdist 函数收到以下错误?
我正在尝试获取在丹麦的两个邮政编码之间旅行所需的时间。出于某种原因,有些组合会起作用,而另一些则不会。对于那些不起作用的,我尝试在谷歌地图上搜索邮政编码以确保它确实存在并且谷歌知道它 - 在这里它会毫无问题地找到它。
当我运行控制台时,控制台会给我以下输出:
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 () ...
同样的例子,它可以按照您的预期工作
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
【问题讨论】: