Heuristic Andrew

This R function uses the free freegeoip.net geocoding service to resolve an IP address (or a vector of them) into country, region, city, zip, latitude, longitude, area and metro codes.

You will just need the rjson package, available from CRAN.

And this demonstrates how to use it:

This code could use more error handling and caching (memoization), but it should work fine for smaller batches. In case you are thinking of large-batch geolocation, freegeoip.net allows 10,000 queries per hour, and it seems a bit slow (at least, from my ISP).

UPDATE: Flodel has developed a generic error handling function for use with freegeoip.

Tested with R 2.15.2 on Ubuntu 13.04.