Inquiry related to processing multiple db file simulataneously
1
0
Entering edit mode
2.1 years ago
rheab1230 ▴ 140

Hello,

I am trying to create a dataframe from many different model file. I want to create dataframe for each tissue with it respective model file. So my first step is to input the .db file and dbgetquery to convert it into dataframe for further use. This is what I am doing

library("RSQLite")
sqlite <- dbDriver("SQLite")
data_files <- list.files("C:/Users/Desktop/Model_files")  # Identify file names
data_files   

en_adrenal.db
en_brain_Cortex.db
en_spleen.db
en_wholeblood.db
and so on
#then use a loop to be able to read in all the db file and create df for each tissue:                                               
for(i in 1:length(data_files)) {                              # Head of for-loop
dbname <-  data_files[i]
#dbname <- "en_Whole_Blood.db" 
db = dbConnect(sqlite,dbname[i])
df[i] <- dbGetQuery(db,"SELECT * FROM weights")
}

But in my case its giving an error.

Error in df[i] <- dbGetQuery(db, "SELECT * FROM weights") : 
object of type 'closure' is not subsettable
In addition: Warning message:
call dbDisconnect() when finished working with a connection 
View(df1)

In my case only one df1 is created rather that individual dataframe for all the tissues. Does anyone know how to deal with this or any advice to solve this error.

sql R • 713 views
ADD COMMENT
0
Entering edit mode
2.1 years ago

how about calling dbDisconnect after dbGetQuery ?

ADD COMMENT
0
Entering edit mode

I did that but it still showing error.

for(i in 1:length(data_files)) {                              # Head of for-loop
+     dbname <- data_files[i]
+     #dbname <- "en_Whole_Blood.db" 
+     db = dbConnect(sqlite,dbname[i])
+     df[i] <- dbGetQuery(db,"SELECT * FROM weights")
+     dbDisconnect(df[i])
+ }

Error in df[i] <- dbGetQuery(db, "SELECT * FROM weights") : 
  object of type 'closure' is not subsettable
ADD REPLY

Login before adding your answer.

Traffic: 1730 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6