可以使用
dplyr
包创建内存数据库:
library(dplyr)
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
copy_to(con, mtcars)
有没有办法将此数据库保存到文件并重新加载?
是的,您可以将数据保存到文件中的本地 SQLite 数据库中。
library(DBI)
library(RSQLite)
# create a connection to a local file named mtcars.db located in user's home folder
conn <- dbConnect(RSQLite::SQLite(), "~/mtcars.db")
# write mtcars data into the local SQLite file
dbWriteTable(conn, "mtcars", mtcars, overwrite = T)
# read the data from the database file into another variable
mtcars2 <- dbReadTable(conn, "mtcars")