Created
June 9, 2011 23:48
-
-
Save ramhiser/1018011 to your computer and use it in GitHub Desktop.
Input data from a SQLite database with RSQLite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library('RSQLite') | |
# Establishes a connection to the specified SQLite database file. | |
db_filename <- "choose_filename.db3" | |
db_driver <- dbDriver("SQLite") | |
db_conn <- dbConnect(db_driver, dbname = db_filename) | |
# An alternative is... (not sure about the difference) | |
# db_conn <- dbConnect(SQLite(), dbname = db_filename) | |
# Reads in the contents for the table "myTable" as a data.frame. | |
myTable <- dbReadTable(db_conn, name = "myTable") | |
# Example query: Queries all of the contents of the "myTable" table. | |
query <- 'SELECT * FROM myTable' | |
results <- dbSendQuery(db_conn, query) | |
proteins <- fetch(results) | |
dbClearResult(results) | |
# Lists all of the tables in the current database. | |
dbListTables(db_conn) | |
# Closes connection to the current database. | |
dbDisconnect(db_conn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment