knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The goal of scdb is to provide a back-end for the sc project.
This is a general common-form data structure for complex hierarchical data.
You can install scdb from github with:
# install.packages("devtools") devtools::install_github("hypertidy/scdb")
This is a basic example which converts a simple features object to a database, then recreates that object in a very scaleable, flexible and extensible way.
library(scdb) data(hpoly) (pdb <- write_db(hpoly))
Now explore the objects available in the database.
library(dplyr) (obj <- tbl(pdb, "object"))
There are three objects, and each has a long ID object_
, as well as other metadata.
Using joins we can access the other data in the decomposed tables.
(p <- tbl(pdb, "vertex") %>% inner_join(tbl(pdb, "path_link_vertex")) %>% inner_join(tbl(pdb, "path")))
In a real case we would wrap the chained joins within a list-column in obj
or similar trick, and use the database more cleverly to only
expand out the data we need for each object. But also note there's no collect
statement, big_tab
is still a promise that the database will do the work only when we really need it to.
library(ggplot2) collect(p) %>% ggplot(aes(x = x_, y = y_, group = path_, colour = path_)) + geom_path() library(ggpolypath) collect(p) %>% ggplot(aes(x = x_, y = y_, group = path_, colour = path_)) + ggpolypath::geom_polypath()
WIP
A future version will provide methods for sc_coord, sc_path, PATH and PRIMITIVE that can work more transparently from a database. In particular this will allow building a completely arbitrary data structure of any size in a database, that can then be streamed into R for analysis or visualization in any of the graphics systems.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.