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_types
is a named vector. Required ifcol_types
is 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. Iftypes
is a named character vector, the column names ofdata
are ignored the names of types used instead.- id
Diagram container id passed to
d2_container()
. Defaults toNULL
. IfNULL
,id
is set torlang::caller_arg(data)
ifdata
is supplied or a random string ifdata = NULL
.- label
Diagram label. Defaults to
id
. If supplied,label
is displayed instead ofid
.- ...
Arguments passed on to
d2_container
lines
Optional diagram text. If supplied
lines
is recycled to match the length ofid
.class
Diagram class
name
Diagram container name
width,height
Diagram width and height (in pixels?)
style
A string or results from the
d2_style()
helper function.icon
Diagram icon
collapse
If
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] "sWLkluue: {\n label: col_types Example\n shape: sql_table\n name: char\n\n num: int\n\n}"