Printing ggproto objects: print.ggproto
Mix.install([
{:giggly, path: Path.join(__DIR__, "..")},
{:kino, "~> 0.19"}
])
About this notebook
This notebook follows the examples on ggplot2's reference page for
print(<ggproto>), which covers
format(<ggproto>) too, in the order the page gives them. Each example shows ggplot2's code
first and then Giggly's. An example Giggly cannot draw yet keeps its ggplot2 code and names what
it is waiting for, so the page is also a list of what remains.
Printing a ggproto object calls the object's own print method if it has one. Otherwise it lists
the object's members, its own and those it inherits: in one flat list by default, or, with
flat = FALSE, level by level up the inheritance. format() returns that listing as text. Not
in Giggly yet: ggproto(), so there are no ggproto objects to print.
An object with a print method
Dog <- ggproto(
print = function(self, n) {
cat("Woof!\n")
}
)
Dog
Printing Dog calls its own print method, which writes Woof!. Not in Giggly yet:
ggproto().
Formatting an object as text
cat(format(Dog), "\n")
format() does not call the object's print method: it describes the object, listing its
members, and cat() writes that text. Not in Giggly yet: ggproto().