Connection to Relations Operators

John Mount

2018-10-26

The cdata operators have some interesting lineage:

The sense we mean the control table is a picture of the transform from “plotting the iris data faceted” is made a bit more obvious if we apply the control table to itself.

library(cdata)

iris <- data.frame(iris)


(controlTable <- wrapr::qchar_frame(
  flower_part, Length      , Width       |
  Petal      , Petal.Length, Petal.Width |
  Sepal      , Sepal.Length, Sepal.Width ))
#>   flower_part       Length       Width
#> 1       Petal Petal.Length Petal.Width
#> 2       Sepal Sepal.Length Sepal.Width

row <- blocks_to_rowrecs(controlTable, 
                         keyColumns = NULL, 
                         controlTable = controlTable)
print(row)
#>   Petal.Length Petal.Width Sepal.Length Sepal.Width
#> 1 Petal.Length Petal.Width Sepal.Length Sepal.Width

# recover the controlTable from the row!
rowrecs_to_blocks(row,
                  controlTable = controlTable)
#>   flower_part       Length       Width
#> 1       Petal Petal.Length Petal.Width
#> 2       Sepal Sepal.Length Sepal.Width

Some discussion of this example and the theory of records in cdata can be found here.