[R] Help to download data from multiple URLs with API key

Bhaskar Mitra bh@@k@r@ko|k@t@ @end|ng |rom gm@||@com
Tue Apr 21 06:39:22 CEST 2020


Hello Everyone,

I am trying to download data from multiple websites using API key.
The  code to download from one URL is given below.

I have a list of multiple URLs' where the suffix URL 'c' keeps changing.

I would appreciate any help on how i can modify the code below that will
allow
 me to read multiple URLs and save the data from each URL as separate
csv file.

thanks,
bhaskar


#-----------------------------------------------------------------------
library(rjson)
setwd(Input)

base_url <- "abcd"         # This remains constant

b <-  "api_key"            # the api key - this remains constant

c <-  "series_id=1"        # Only this suffix URL changes.  I have a list
of multiple such URL's with different series ids.


full_url = paste0(base_url,
                  b,
                  c)


d3 <- lapply(fromJSON(file=full_url)[[2]], function(x) c(x["data"]))
d3 <- do.call(rbind, d3)

b <- as.data.frame(unlist(d3))
write.csv(b)

#-----------------------------------------------------------------------

	[[alternative HTML version deleted]]



More information about the R-help mailing list