An S3 value object (class kit_code): code text plus a version name. It has an
htmltools::as.tags() method: put it straight into a page and it renders a line with "version
name (bold) + Copy" and the code box below, with the code first wrapped by kit_code_wrap() to
at most 70 columns per line (Chinese characters count as 2).
If a line is still too long after wrapping (e.g. a long string that cannot be broken), it gives
a warning (it does not stop), and the box scrolls sideways.
Arguments
- code
The code (a character vector; one element per line, or containing newlines).
- label
The version name, e.g. "tidyverse 版" ("tidyverse version"), "base R 版" ("base R version"), "kits 版" ("kits version").
- width
Maximum columns per line;
NULLmeans no wrapping and no check.- x
A
kit_codeobject.- ...
Not used.
Examples
x <- kit_code("joined <- dplyr::left_join(t1, t2, by = \"id\")", "tidyverse 版")
x
#> ## tidyverse 版
#> joined <- dplyr::left_join(t1, t2, by = "id")
htmltools::as.tags(x)
#> <div class="kit-code-head">
#> <strong>tidyverse 版</strong>
#> <button type="button" class="btn btn-sm btn-outline-secondary kit-copy">複製</button>
#> </div>
#> <pre><code>joined <- dplyr::left_join(t1, t2, by = "id")</code></pre>