There are several ways to geocode addresses from R, but the easiest (and cheapest) way is with the {tidygeocoder} package and one of the city’s internal locators.
Note
The locator will only geocode San Francisco addresses.
library(tidygeocoder)library(sf)
Linking to GEOS 3.9.1, GDAL 3.4.3, PROJ 7.2.1; sf_use_s2() is TRUE
If you need to geocode addresses outside the city, the geocodio service is a nice option, but you’ll first need to obtain your API key. Sign up for an account and register for an API key. Once you have it, you need to put it in your .Renviron file, a special text file that runs every time you open/restart R.
Edit your .Renviron file with the usethis package:
library(usethis)edit_r_environ() # this opens the file in RStudio
Paste your API key like so:
GEOCODIO_API_KEY='<your_api_key>'
Save the file and restart R. You should then be able to call geocode with the method = 'geocodio' argument. Note that there is a rate limit of 1000 addresses per hour.