0

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?

4

1 回答 1

0

尝试一个额外的逻辑限定符向量:

database.files<- dir(database.path)
database.files <- database.files[grep(".db$",database.files, perl = T) &
                                 file.info(database.files)[,"size"] > 0 ]

?file.info

如果错误是由于处理而发生的,那么您需要查看?tryR 提供的各种错误处理能力。

于 2014-05-27T05:56:51.750 回答