求助:安装GitHub版ggmap后mapdist()报subscript out of bounds错误
subscript out of bounds Error in ggmap's mapdist() After Installing GitHub Version Hey there, let's work through this frustrating error you're facing with the development version of ggmap. Here are some actionable steps to resolve the Error in tmp[[c(1, 1)]] : subscript out of bounds issue:
Double-check your Google API setup
Even if you haven't hit the API limit, the GitHub version of ggmap might have updated how it interacts with Google's APIs. Make sure you've properly registered your API key withggmap::register_google(key = "YOUR_VALID_API_KEY"), and confirm that the Google Directions API is enabled in your Google Cloud Console (this is required formapdist()to work). Sometimes a quick re-registration can fix unexpected parsing issues.Roll back to the CRAN version temporarily
To rule out a bug in the development build, revert to the stable CRAN version with:install.packages("ggmap")Restart your R session after installation, then test your original
mapdist()call again. If this works, the issue is likely specific to the GitHub branch you installed—you can keep using the CRAN version until the bug is fixed upstream.Standardize your input addresses
The updated version might have stricter address parsing logic. Try adding location context (like country codes) to your origin/destination to avoid ambiguity:mapdist('Manchester Deaf Institute, Manchester, UK', 'Birmingham O2 Academy 1, Birmingham, UK', mode = 'driving')Sometimes minor formatting tweaks can help the API return the expected response structure.
Debug the raw API response
To see exactly what's causing the subscript error, you can manually call the Google Directions API and inspect the output. Use thehttrpackage to fetch the raw data:library(httr) api_key <- "YOUR_API_KEY" origin <- URLencode("Manchester Deaf Institute") destination <- URLencode("Birmingham O2 Academy 1") url <- paste0("https://maps.googleapis.com/maps/api/directions/json?origin=", origin, "&destination=", destination, "&mode=driving&key=", api_key) response <- GET(url) raw_data <- content(response) str(raw_data)Look for missing
routesorlegsentries in the response—if the API returns an unexpected structure (like no route found, even though you know one exists), that could be triggering the subscript out of bounds error.Check for known issues in the ggmap repo
Head over to the ggmap GitHub repository's issues section to see if other users have reported the same error. There might be a pending fix or a temporary workaround shared by the community or the package author.
内容的提问来源于stack exchange,提问作者Polly

