0

I've downloaded all the url's for the different drug-event pairs, but they all end in .zip. Does anyone know how to automate pulling the .json file out of these zip files without doing it manually for each one? I'm not sure how to unzip the files.

library(jsonlite)
# create a character vector of all 961 available download files
url <- "https://api.fda.gov/download.json"
document <- fromJSON(url)
results <- document$results
drug_event <- results$drug$event
files <- as.character(drug_event$partitions$file)

# unzipping the files
file1 <- files[1]
temp <- tempfile()
download.file(file1,temp)
unz(temp, "data.json")
3

Just use for:

# unzipping the files
temp<-tempfile()
for (f in files) {
    download.file(f,temp)
    unzip(temp)
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.