R:Check existence of “today’s” file and if it doesn’t exist, download it

I think this an issue with encoding the result of download.file, one way could be to use fread to get the data then write it with fwrite:

#Look for COVID file starting with "data_"
destfile <- list.files(pattern = "data_") 
#Find file date
fileDate <- file.info(destfile)$ctime %>% as.Date()
#>[1] "2020-11-06" "2020-11-06" "2020-11-06"

if(!length(destfile) | max(fileDate) != today()){
  COVIDdata <- fread(fileURL)
  fwrite(COVIDdata, file = paste0("data_",today(),".csv"))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top