Skip to content

Instantly share code, notes, and snippets.

@cutterkom
Created June 3, 2023 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cutterkom/e1eb51259d21f383a6736258d2333e51 to your computer and use it in GitHub Desktop.
Save cutterkom/e1eb51259d21f383a6736258d2333e51 to your computer and use it in GitHub Desktop.
Create sqlite from R dataframes
library(DBI)
library(tidyverse)
# Import SPSS -------------------------------------------------------------
cleaned_dataframe_with_spss_data <- ....
# Write to DB -------------------------------------------------------------
import <- cleaned_dataframe_with_spss_data
# creates db.sqlite file if it doesn't exist
con <- dbConnect(RSQLite::SQLite(), "db.sqlite")
dbWriteTable(con, "tbl_name", import)
dbDisconnect(con)
# Query data --------------------------------------------------------------
con <- dbConnect(RSQLite::SQLite(), "db.sqlite")
local_df <- tb(con, "tbl_name") %>%
filter(...) %>%
collect()
dbDisconnect(con)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment