Adding a bit to @cderv already great answer, you don't need to even write a function to extract your elements yourself. Internally, purrr will convert them to very similar function anyway if you provide it with the vector of what you want to extract like so:
map(l, c("results", "geometry", "location"))
map(l, c("results", "geometry", "viewport"))
The result is just as easy to handle:
loc <- structure(list(results = structure(list(address_components = list(
structure(list(long_name = c("151", "3rd Street", "South Beach",
"San Francisco", "San Francisco County", "California", "United States",
"94103", "3107"), short_name = c("151", "3rd St", "South Beach",
"SF", "San Francisco County", "CA", "US", "94103", "3107"
), types = list("street_number", "route", c("neighborhood",
"political"), c("locality", "political"), c("administrative_area_level_2",
"political"), c("administrative_area_level_1", "political"
), c("country", "political"), "postal_code", "postal_code_suffix")), .Names = c("long_name",
"short_name", "types"), class = "data.frame", row.names = c(NA,
9L))), formatted_address = "151 3rd St, San Francisco, CA 94103, USA",
geometry = structure(list(location = structure(list(lat = 37.7859072,
lng = -122.4008003), .Names = c("lat", "lng"), class = "data.frame", row.names = 1L),
location_type = "ROOFTOP", viewport = structure(list(
northeast = structure(list(lat = 37.7872561802915,
lng = -122.399451319709), .Names = c("lat", "lng"
), class = "data.frame", row.names = 1L), southwest = structure(list(
lat = 37.7845582197085, lng = -122.402149280291), .Names = c("lat",
"lng"), class = "data.frame", row.names = 1L)), .Names = c("northeast",
"southwest"), class = "data.frame", row.names = 1L)), .Names = c("location",
"location_type", "viewport"), class = "data.frame", row.names = 1L),
place_id = "ChIJ23gaZn2AhYARH-8DeKxyEw0", plus_code = structure(list(
compound_code = "QHPX+9M South of Market, San Francisco, CA, United States",
global_code = "849VQHPX+9M"), .Names = c("compound_code",
"global_code"), class = "data.frame", row.names = 1L), types = list(
"street_address")), .Names = c("address_components",
"formatted_address", "geometry", "place_id", "plus_code", "types"
), class = "data.frame", row.names = 1L), status = "OK"), .Names = c("results",
"status"))
l <- list(loc, loc, loc)
library(purrr)
map(l, c("results", "geometry", "location"))
#> [[1]]
#> lat lng
#> 1 37.78591 -122.4008
#>
#> [[2]]
#> lat lng
#> 1 37.78591 -122.4008
#>
#> [[3]]
#> lat lng
#> 1 37.78591 -122.4008
map(l, c("results", "geometry", "viewport"))
#> [[1]]
#> northeast.lat northeast.lng southwest.lat southwest.lng
#> 1 37.78726 -122.3995 37.78456 -122.4021
#>
#> [[2]]
#> northeast.lat northeast.lng southwest.lat southwest.lng
#> 1 37.78726 -122.3995 37.78456 -122.4021
#>
#> [[3]]
#> northeast.lat northeast.lng southwest.lat southwest.lng
#> 1 37.78726 -122.3995 37.78456 -122.4021
Created on 2018-10-25 by the reprex package (v0.2.1)