Pull data from Socrata database with $where query from vector

56 Views Asked by At

how can I use a vector to select multiple unique kentekens in RSocrata?

The following function works fine, where the where argument allows me to filter on a single kenteken value.

kentekens <- RSocrata::read.socrata(
  "https://opendata.rdw.nl/resource/m9d7-ebf2.json?$where=kenteken = '0001ES'")

However, I have a vector of (nearly 2000) kentekens of which I want to obtain information from this database. Is it possible to query for this vector, and if so, how?

1

There are 1 best solutions below

0
On

Unfortunately, RSocrata does not offer a way to support R objects in the query. Howevery, it is rather simple to build a for loop and query each kenteken individually.

vector_kentekens <- c("0001ES", "0001TJ", "0001WF", "0002GV", "0003ZB")

df_kentekens <- c()

for(kenteken in vector_kentekens ){
  RequestRDW <- RSocrata::read.socrata(
    url = paste(sep = "", "https://opendata.rdw.nl/resource/m9d7-ebf2.json?$select=kenteken,voertuigsoort&$where=kenteken = '", kenteken, "'")
    )
  df_kentekens <- rbind(df_kentekens, RequestRDW)
}