Geocoding addresses using R
You have just learned how to query a web service via raw GET
requests to the endpoint and via a handy SDK using Python. As you can already guess, you can also do both with R. Let's see how it's done.
Using an explicit GET request
The package that allows calls to URLs in R is httr
(installed by default with the engine). Making a GET
request simply translates to GET(your_url)
thanks to it. As you have already seen in the previous sections, percent encoding must be applied to the address to be passed as a web parameter to the Bing Maps Locations API endpoint. The function that allows you to apply this type of encoding to a string is found in the RCurl
package and is named curlPercentEncode()
. In addition, the handy tictoc
package will be used to measure run times. Both the RCurl
and tictoc
packages need to be installed, as shown in the following steps:
- Open RStudio and make sure it is referencing your latest CRAN R engine in Global Options...