How do I check the existence of a downloaded file

前端 未结 3 1510
刺人心
刺人心 2020-12-08 04:00

I\'ve created a R markdown file that starts by loading a file from the web. I found the cache=TRUE to be a little flaky so I want to put an if condition in to check for the

相关标签:
3条回答
  • 2020-12-08 04:09

    You can use tryCatch

      if(!file.exists(destfile)){
        res <- tryCatch(download.file(fileURL,
                                  destfile="./data/samsungData.rda",
                                  method="auto"),
                    error=function(e) 1)
        if(dat!=1) load("./data/samsungData.rda") 
    }
    
    0 讨论(0)
  • 2020-12-08 04:30

    As per the answer given by @agstudy

     destfile="./data/samsungData.rda" 
     fileURL <-
     "https://dl.dropbox.com/u/7710864/courseraPublic/samsungData.rda"   
     if (!file.exists(destfile)) {
        setInternet2(TRUE)
        download.file(fileURL ,destfile,method="auto") }
        load("./data/samsungData.rda")
     }
     load(destfile)
    
    0 讨论(0)
  • 2020-12-08 04:33

    An easy way to check the existence of a file in your working directory is: which(list.files() == "nameoffile.csv")

    This doesn't exactly answer his question but I thought this might be helpful to someone who simply wants to check if a particular file is there in their directory.

    0 讨论(0)
提交回复
热议问题