Created
June 3, 2023 17:00
-
-
Save cutterkom/e1eb51259d21f383a6736258d2333e51 to your computer and use it in GitHub Desktop.
Create sqlite from R dataframes
This file contains hidden or 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(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