Title: | Store Tables in SQL Database |
---|---|
Description: | Provides functions for quickly writing (and reading back) a data.frame to file in 'SQLite' format. The name stands for *Store Tables using 'SQLite'*, or alternatively for *Quick Store Tables* (either way, it could be pronounced as *Quest*). For data.frames containing the supported data types it is intended to work as a drop-in replacement for the 'write_*()' and 'read_*()' functions provided by similar packages. |
Authors: | Magnus Thor Torfason |
Maintainer: | Magnus Thor Torfason <[email protected]> |
License: | MIT + file LICENCE |
Version: | 0.1.3.9001 |
Built: | 2024-10-29 03:15:33 UTC |
Source: | https://github.com/torfason/qst |
This package provides functions for quickly writing (and reading)
back a data.frame
to file in sqlite
format. The name stands
for Store Tables using SQLite', or alternatively for Quick
Store Tables (either way, it could be pronounced as Quest).
For data.frames
containing the supported data
types it is intended to work as a drop-in replacement for the
write_*()
and read_*()
functions provided by packages such
as fst
, feather
, qs
, and readr
packages (as well as the
writeRDS()
and readRDS()
functions).
This function reads a data.frame from an SQLite database. The database has one table, named data, containing the data. Additional tables, prefixed with meta_, may be added in the future to support additional data types not supported in a native way by SQLite.
By specifying lazy=TRUE, the data.frame will not be read into memory on the read operation, but instead a lazy evaluated data.frame will be returned. This results in a near-instantaneous read operation, but subsequent operation will then be done from disk using SQL translation when the data.frame is passed to other functions or collect() is called on it.
Note that types apart from the core types, integer, numeric and character are not currently supported with lazy=TRUE. They will be converted to the core types with a warning.
read_qst(path, lazy = FALSE)
read_qst(path, lazy = FALSE)
path |
The path to read from. |
lazy |
If TRUE, the full data.frame will not be read into memory, but instead a lazy evaluated data.frame will be returned. |
A data.frame read from the SQLite file found at path
# Write the cars data set to a file, then read it back cars_db <- tempfile() write_qst(cars, cars_db, indexes=list("speed")) dat <- read_qst(cars_db) unlink(cars_db)
# Write the cars data set to a file, then read it back cars_db <- tempfile() write_qst(cars, cars_db, indexes=list("speed")) dat <- read_qst(cars_db) unlink(cars_db)
This function writes a data.frame to an SQLite database. The database has one table, named data, containing the data. Additional tables, prefixed with meta_, may be added in the future to support additional data types not supported in a native way by SQLite.
write_qst(x, path, ..., unique_indexes = NULL, indexes = NULL)
write_qst(x, path, ..., unique_indexes = NULL, indexes = NULL)
x |
A data.frame to be written to file. Supported column types are integer, numeric and character. |
path |
The path to write to. |
... |
Other parameters passed to methods. |
unique_indexes |
A list of character vectors. Each element of the list will create a new unique index over the specified column(s). Duplicate rows will result in failure. |
indexes |
A list of character vectors. Each element of the list will create a new index. |
The original data frame passed in x
# Write the cars data set to a file cars_db <- tempfile() write_qst(cars, cars_db, indexes=list("speed")) unlink(cars_db)
# Write the cars data set to a file cars_db <- tempfile() write_qst(cars, cars_db, indexes=list("speed")) unlink(cars_db)