Skip to content

Instantly share code, notes, and snippets.

@cecilialee
Created March 2, 2018 06:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cecilialee/db5d631e284245fd2069c3a0491e0272 to your computer and use it in GitHub Desktop.
Save cecilialee/db5d631e284245fd2069c3a0491e0272 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment