Hi All. Can't figure out what's quite wrong with my loop and conditionals. Basically I want to check to see if a file exists, if it does, read it in and send to a database. There are 3 files and I want to load all 3. If I have not yet loaded all 3, I want it to keep running till the job is done. Here's my code.
x <- 0
while(x != 3){
if(file.exists(file1.csv)) {
file1<- fread("file1.csv", stringsasfactors = FALSE)
sqlSave(con, file1, tablename = 'dbo.file1', colnames = FALSE, rownames = FALSE, append = TRUE)
x = x + 1
} else if(file.exists(file2.csv)) {
file2<- fread("file2.csv", stringsasfactors = FALSE)
sqlSave(con, file2, tablename = "dm.file2", colnames = FALSE, rownames = FALSE, append = TRUE)
x = x + 1
} else if(file.exists(file3.csv)) {
file3<- fread("file3.csv", stringsasfactors = FALSE)
sqlSave(con, file3, tablename = "dm.file3", colnames = FALSE, rownames = FALSE, append = TRUE)
x = x + 1
}
}
My idea was to have each successful condition/load add 1 to x. So when X got to 3, it knew to stop.
Thanks in advance.