[R] RSQLite +textConnection()

Alexander Nervedi alexnerdy at hotmail.com
Tue Nov 28 22:12:06 CET 2006


Hi Seth,

Thank you for taking the trouble to look. I have created some code that 
simulates the problem. SOme additional observations are:

a) After giving the error "Error in textConnection(readLines(f, n = 2)) : 
all connections are in use" I cannot ask for sessionInfo(). I get the error 
message
>sessionInfo()
Error in gzfile(file, "rb") : all connections are in use

So I am presenting the sessionInfo() output after reading in the first 124 
files.

>sessionInfo()
R version 2.4.0 (2006-10-03)
i686-pc-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "base"

other attached packages:
RSQLite      DBI
"0.4-1" "0.1-10"

Next, below is the code that I used to generate this. Its not too big so i 
just pasted it into the email. it creates 130 files first and then tries to 
read them in and save them in alexander.db, it then performs a query and 
then closes.

Hopefully, this will be helpful in tracking down the source of the problem.

thank you,

Alex.

# R Script

test.dir <- "/home/alex/test"
setwd(test.dir)
N  <- 130
dat <-data.frame(ID = 1:N, Marks = runif(N)*100, Class = sample(c("I", 
"II","III","IV"),size = N, replace = TRUE) )
for (i in 1:N){
    write.csv(dat[i,], paste("test-", i,".csv", sep = ""), row.names = 
FALSE)
}

# getting the filenames
filename <- list.files()
library(RSQLite)
driver<-dbDriver("SQLite")
connect<-dbConnect(driver, dbname = "alexander.db")

lapply(filename[1:124], FUN = function(x){
        cat(paste("doing",x, "\n"))
        testID <- as.data.frame((scan(file = x, what = list(ID = 1, Marks = 
35.0861437153071, Class = "II"), skip = 1, sep = ",")))
        dbWriteTable(connect, "grades", testID, row.names = FALSE, append = 
TRUE, eol = "\r\n" )
    })

# LIST ALL TABLES IN THE DATABASE
dbListTables(connect)

# QUERY DATA AGAINST TBL_ratings IN THE DATABASE
query01<-dbSendQuery(connect, statement = "select * from tbl_ratings");

# FETCH 10 RECORDS OF DATA INTO A DATA FRAME
(data01<-fetch(query01, n = 10));

# CLOSE THE CONNECTION
sqliteCloseConnection(connect);



>From: Seth Falcon <sfalcon at fhcrc.org>
>To: "Alexander Nervedi" <alexnerdy at hotmail.com>
>CC: sfalcon at fhcrc.org, r-help at stat.math.ethz.ch
>Subject: Re: [R] RSQLite +textConnection()
>Date: Mon, 27 Nov 2006 21:50:23 -0800
>
>"Alexander Nervedi" <alexnerdy at hotmail.com> writes:
>
> > They are uptodate. When I run it on windows the i can load upto 200
> > files, while on Linux it stops after loading 125.
>
>Could you provide as much of a reproducible example as possible (along
>with sessionInfo())?  I will try and have a look.
>
>+ seth



More information about the R-help mailing list