When using the function google_places, the location argument is a vector of coordinate pairs. However, within this function I wrote, an error is returned:
Error in validateGeocodeLocation(location) :
location must be a vector of a pair of latitude and longitude coordinates
This is the simple command that WORKS outside my function. I use c(39, -105).
search <- google_places(search_string = "Urgent care center", key = key, location = c(39, -105), radius = 50000)
This is the function I wrote that will return the error:
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)
Here, thin_df is a function I wrote which runs smoothly and returns the desired dataframe:
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
Why could this possibly be happening if the error references the location argument, which works outside the function with no change?
Thank you!
You've mixed up the argument order in the
google_places()function.This is the function definition
Notice
locationis the 2nd argument, but in yourfull_searchfunction you're supplying thekeyto the 2nd argument.I would always recommend explicitely stating the argument when you call functions