This is a follow-up from doing multiple fromJSON queries (jsonlite). Not sure if it's ok to post separate but related questions.
following @parfait 's suggestion, I tried to create a list of URLs in a list so that fromJSON can be applied to it. However I faced an error
library(jsonlite)
library(BBmisc)
library(readxl)
# reading an excel file with 1 column of URLs
sample_postal_code <- read_excel("~/Desktop/sample postal code.xlsx")
https://drive.google.com/open?id=1BC2JHKg03DReFdCN-Ru-cTrxXXOZ1ZTw
dataset <- convertRowsToList(sample_postal_code[-1])
dataset <- unlist(dataset,recursive = F)
json_list2 <- lapply(dataset, function(i) fromJSON(i)$results)
=> Error in open.connection(con, "rb") : HTTP error 400.
For the record, the following code worked:
library(jsonlite)
x1 <- as.character("https://developers.onemap.sg/commonapi/search?searchVal=revenue&returnGeom=Y&getAddrDetails=Y&pageNum=1)")
x2 <- as.character("https://developers.onemap.sg/commonapi/search?searchVal=airport&returnGeom=Y&getAddrDetails=Y&pageNum=1)")
url_list <- list(x1,x2)
json_list <- lapply(url_list, function(i) fromJSON(i)$results)
df = Reduce(function(...) merge (... , all=T),json_list)
I notice under the drop-down in url_list that it has
: chr "https://developers.onemap.sg/commonapi/search?searchVal=revenue&returnGeom=Y&getAddrDetails=Y&pageNum=1)"
: chr "https://developers.onemap.sg/commonapi/search?searchVal=airport&returnGeom=Y&getAddrDetails=Y&pageNum=1)"
then x1 and x2 below, while dataset has:
1 : chr "https://..."
2 : chr "https://..."
and so on. Does anyone know what the problem is? Thanks!