r - How to import CSV into sqlite using RSqlite? -


as question, found can use .import in sqlite shell, seems not working in r environment, suggestions?

you can use read.csv.sql in sqldf package. 1 line of code read. assuming want create new database, testingdb, , read file try this:

# create test file write.table(iris, "iris.csv", sep = ",", quote = false, row.names = false)  # create empty database. # can skip step if database exists. sqldf("attach testingdb new") # or: cat(file = "testingdb")  # read table called iris in testingdb sqlite database library(sqldf) read.csv.sql("iris.csv", sql = "create table main.iris select * file",    dbname = "testingdb")  # @ first 3 lines sqldf("select * main.iris limit 3", dbname = "testingdb") 

the above uses sqldf uses rsqlite. can use rsqlite directly. see ?dbwritetable in rsqlite. note there can problems line endings if directly dbwritetable sqldf automatically handle (usually).

if intention read file r after reading database , don't need database after see:

http://code.google.com/p/sqldf/#example_13._read.csv.sql_and_read.csv2.sql


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -