Create a D2 SQL Table Diagram
Usage
d2_sql_table(
data = NULL,
visibility = NULL,
col_types = vec_ptype_abbr,
id = NULL,
label = id,
...
)Arguments
- data
A data frame used for column names and types. Ignored if
col_typesis a named vector. Required ifcol_typesis unnamed or a function.- visibility
One or more of: , +, -, #. Length is recycled to match the number of columns in
data.- col_types
A named character vector, an unnamed character vector with the same length as the number of columns in
data, or a function that returns a character vector based on the columns fromdata. Defaults to vctrs::vec_ptype_abbr. Other recommended options are vctrs::vec_ptype_full or base::typeof. Iftypesis a named character vector, the column names ofdataare ignored the names of types used instead.- id
Diagram container id passed to
d2_container(). Defaults toNULL. IfNULL,idis set torlang::caller_arg(data)ifdatais supplied or a random string ifdata = NULL.- label
Diagram label. Defaults to
id. If supplied,labelis displayed instead ofid.- ...
Arguments passed on to
d2_containerlinesOptional diagram text. If supplied
linesis recycled to match the length ofid.classDiagram class
nameDiagram container name
width,heightDiagram width and height (in pixels?)
styleA string or results from the
d2_style()helper function.iconDiagram icon
collapseIf
collapse = "\n", return a string with D2 diagram code for a container. Ifcollapse = NULL(default), return a character vector with the same length as id.
Examples
d2_sql_table(mtcars[, 1:4])
#> [1] "\"mtcars[, 1:4]\": {\n label: \"mtcars[, 1:4]\"\n shape: sql_table\n mpg: dbl\n\n cyl: dbl\n\n disp: dbl\n\n hp: dbl\n\n}"
d2_sql_table(
label = "col_types Example",
col_types = c("name" = "char", "num" = "int")
)
#> [1] "eDlIEEXO: {\n label: col_types Example\n shape: sql_table\n name: char\n\n num: int\n\n}"