3

I have a SQLite database pisa06.db created from a data frame. I would like to read variables (columns) from this database file selectively without actually loading into memory. I know I can do it with a data frame already in the workspace. I couldn't figured out how to do it with a database in the disk without reading the whole database.

Let me give you more detail. I have a data frame pisa06. I created a database file pisa06.db in the working directory with

library(sqldf)
drv <- dbDriver("SQLite") 
con <- dbConnect(drv, "pisa06.db") 
dbWriteTable(con, "pisa06", pisa06)

Now I need to reach this database file and read some variables into a data frame without reading the whole database. I have tried many alternatives. This will not work:

df <- sqldf("select CNT, SCHOOLID from pisa06", drv="SQLite")

How can I use sqldffor this purpose? Is this the best way to do it?

1 Answer 1

4

Using RSQLite package:

library(RSQLite)

con <- dbConnect(SQLite(), dbname = "pisa06.db")
dbGetQuery(con,"select CNT, SCHOOLID from pisa06")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.