cecilialee
3/2/2018 - 6:57 AM

Import CSV to Sqlite with sqldf in R

Import CSV to Sqlite with sqldf in R. #r

# create a test file
write.table(iris, "iris.csv", sep = ",", quote = FALSE, row.names = FALSE)

# create an empty database.
# can skip this step if database already exists.
sqldf("attach testingdb as new")
# or: cat(file = "testingdb")

# read into table called iris in the testingdb sqlite database
library(sqldf)
read.csv.sql("iris.csv", sql = "create table main.iris as select * from file", 
  dbname = "testingdb")

# look at first three lines
sqldf("select * from main.iris limit 3", dbname = "testingdb")


# https://stackoverflow.com/questions/4332976/how-to-import-csv-into-sqlite-using-rsqlite