Error: (list) object cannot be coerced to type 'integer'

橙三吉。 提交于 2020-02-02 12:52:48

问题


I am getting this error in R when I try to run the function route() within a loop:

Error: (list) object cannot be coerced to type 'integer'

The function is found in the package "ggmap". It takes two strings as an argument and searches on google maps the directions between them. It returns a dataframe which contains information about the route including distance, minutes, coordinates etc.

I have a vector with many strings which represent postcodes and I am using this route() function within a loop on those postcodes. It runs ok for the first 40 or so searches, but then it crashes giving the above error.

df <- as.data.frame(read.csv("df.csv", sep=","))

for (i in df$post_code){
  route(i,'NE29 8NH', structure = 'route', mode = 'driving')
}

I checked the vector with postcodes and there are no missing values or other anomalies. Please help me with this.


回答1:


I believe the issue has to do with google maps rate limits, just enter the request URL and refresh the browser a few times and you will get the below message:

{
   "error_message" : "You have exceeded your rate-limit for this API.",
   "routes" : [],
   "status" : "OVER_QUERY_LIMIT"
}

ggmaps tries to parse the json response, but the response doesn't have any information. I would suggest forcing a delay in your loop with Sys.sleep(x), x<-seconds.



来源:https://stackoverflow.com/questions/25083512/error-list-object-cannot-be-coerced-to-type-integer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!