使用函数google_places时,位置参数是坐标对的向量。然而,在我编写的这个函数中,返回了一个错误:
Error in validateGeocodeLocation(location) :
location must be a vector of a pair of latitude and longitude coordinates
这是一个在我的功能之外工作的简单命令。我用c(39,-105(。
search <- google_places(search_string = "Urgent care center", key = key, location = c(39, -105), radius = 50000)
这是我写的函数,它将返回错误:
full_search <- function(search_string,
key, location, radius){
call_1 <- google_places(search_string,
key,
location,
radius)
thin1 <- thin_df(call_1)
return(thin1)}
full_search("Urgent care center", key, c(39, -105), 50000)
这里,thin_df是我编写的一个函数,它运行平稳并返回所需的数据帧:
thin_df(search)
name lat lon
1 UCHealth Urgent Care - Garden of the Gods 38.89643 -104.8416
2 UCHealth Urgent Care - Circle Square 38.79420 -104.7879
3 Penrose Community Urgent Care 38.87440 -104.7936
4 UCHealth Urgent Care - Powers 38.89424 -104.7211
5 Emergicare Austin Bluffs 38.89066 -104.7548
6 UCHealth Urgent Care - Voyager Parkway 39.02628 -104.8166
7 QwikCare MD Urgent Care 38.89746 -104.8274
8 Woodmen Medical Park 38.94013 -104.7504
9 Centura Health Urgent Care Fountain 38.71720 -104.7009
10 AFC Urgent Care Castle Rock 39.41698 -104.8799
11 Powers Pointe Urgent Care 38.89393 -104.7234
12 UCHealth Urgent Care - Castle Rock 39.40604 -104.8559
13 QwikCareMD Urgent Care Center 38.91051 -104.7207
14 Centura Health Urgent Care Broadmoor 38.79425 -104.8042
15 Optum Urgent Care 38.87492 -104.7956
16 Wik Care Md Urgent Care Center 38.76717 -104.8158
17 Colorado Urgent Care Associates PC 38.87430 -104.7937
18 Urgent CareX 38.85588 -104.7937
19 Falcon Urgent Care 38.93956 -104.6041
20 Optum Urgent Care 39.06502 -104.8481
如果错误引用了location参数,而该参数在函数外工作而没有更改,为什么会发生这种情况?
谢谢!
您混淆了google_places()
函数中的参数顺序。
这是的功能定义
google_places (search_string = NULL, location = NULL, radius = NULL,
rankby = NULL, keyword = NULL, language = NULL, name = NULL,
place_type = NULL, price_range = NULL, open_now = NULL, page_token = NULL,
simplify = TRUE, curl_proxy = NULL, key = get_api_key("places"),
radar = NULL)
请注意,location
是第二个参数,但在full_search
函数中,您将key
提供给第二个变量。
我总是建议在调用函数时明确说明参数
library(googleway)
key <- secret::get_secret("GOOGLE")
full_search <- function(search_string,
key, location, radius){
call_1 <- google_places(search_string = search_string,
key = key,
location = location,
radius = radius)
return(call_1)
# thin1 <- thin_df(call_1)
# return(thin1)
}
full_search("Urgent care center", key, c(39, -105), 50000)