I load several databasefiles (SQLite) and subject them to a simple query:
library("RSQLite")
drv <- dbDriver ("SQLite")
get.wa2 <- function(file){
con <- dbConnect (drv, dbname = file)
table <- dbGetQuery (con, "Select data3 from data where data2 like 'xxx' ")
return(table)
}
database.files<- dir(database.path)
database.files <- database.files[grep(".db$",database.files, perl = T)] ### select only database files
count.wa <- sapply(database.files,get.wa2)
I run into problems since my files are randomly corrupted, or wiped.. appearing as 0 byte in filesize.
Am I doing something wrong and should I be closing connections after each query. What is best practice here?