---
title: "cdata"
author: "John Mount, Win-Vector LLC"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{cdata}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

The `cdata` package is a demonstration of the ["coordinatized data" theory](http://winvector.github.io/FluidData/RowsAndColumns.html) and includes an implementation of the ["fluid data" methodology](http://winvector.github.io/FluidData/FluidData.html).   The recommended tutorial is: [Fluid data reshaping with cdata](http://winvector.github.io/FluidData/FluidDataReshapingWithCdata.html). We also have a [short free cdata screencast](https://youtu.be/4cYbP3kbc0k) (and another example can be found [here](http://winvector.github.io/FluidData/DataWranglingAtScale.html)).


Briefly `cdata` supplies data transform operators that:

 * Work on local data or with any `DBI` data source.
 * Are powerful generalizations of the operators commonly called `pivot` and `un-pivot`.

A quick example:

```{r chkpkg}
run_vignette <- requireNamespace("RSQLite", quietly = TRUE) &&
  requireNamespace("DBI", quietly = TRUE)
```

```{r ex1, eval=run_vignette}
library("cdata")
my_db <- DBI::dbConnect(RSQLite::SQLite(), 
                        ":memory:")

# pivot example
d <- build_frame(
   "meas", "val" /
   "AUC" , 0.6   /
   "R2"  , 0.2   )

DBI::dbWriteTable(my_db,
                  'd',
                  d,
                  temporary = TRUE)
qlook(my_db, 'd')

cT <- build_pivot_control_q('d',
                            columnToTakeKeysFrom= 'meas',
                            columnToTakeValuesFrom= 'val',
                            my_db = my_db)
tab <- blocks_to_rowrecs_q('d',
                           keyColumns = NULL,
                           controlTable = cT,
                           my_db = my_db)
qlook(my_db, tab)

DBI::dbDisconnect(my_db)
```

Install via CRAN:

```{r, eval=FALSE}
install.packages("cdata")
```

Note: `cdata` is targeted at data with "tame column names" (column names that are valid both in databases, and as `R` unquoted variable names) and basic types (column values that are simple `R` types such as `character`, `numeric`, `logical`, and so on). 


