I'm trying to calculate walk score using walkscoreAPI for multiple Long/Lat pairs. However, the function getWS on takes the first input in the dataframe.
getWS produces a list product, like below.
$status
[1] 1
$walkscore
[1] 0
$description
[1] "Car-Dependent"
$updated
[1] "2017-06-08 22:49:20.313160"
$snappedLong
[1] 38.943
$snappedLat
[1] -77.076
With that in mind I tried to create my own function that would extract $walkscore from the list.
walkscore <- function(x, y){
walk <- getWS(x, y, "YOUR API KEY")
walk$walkscore
}
I then attempted to use this in a simple mutate calculation.
library(walkscoreAPI)
library(tidyverse)
# Create sample df
lat <- c(38.942523, 37.942523)
long <- c(-77.076403, -78.076403)
df <- tibble(
long,
lat)
#Calculate score
df1 <- df %>%
mutate(score = walkscore(long, lat))
This throws the following error
Error: invalid 'description' argument
In addition: Warning message:
In if (file == "") file <- stdin() else { :
the condition has length > 1 and only the first element will be used
How can I rewrite this to run getWS for the whole df and pull $walkscore for each row?