Content of "How to do it in R": a note plus code in one or more versions (with "Copy")
Source:R/code.R
kit_code_blocks.RdEach version is a kit_code(): a line with "version name (bold) + Copy" and the code box below
it; two versions are stacked vertically. Code lines are at most 70 columns (kit_code_wrap());
ligatures are always turned off.
Arguments
- snips
The code: a string, a
kit_code()object, or a named list / character vector of them (names are version names). kitJoin'slist(tidy = , base = )is labeled "tidyverse 版" ("tidyverse version") and "base R 版" ("base R version");NULLversions are skipped (e.g. withbase = NULLthere is only the tidyverse version). Without names the version name is "R".- note
A one-line note at the top;
NULLshows nothing.- width
Maximum columns per line;
NULLmeans no wrapping and no check.
Examples
kit_code_blocks(list(
tidy = "joined <- dplyr::left_join(t1, t2, by = \"id\")",
base = "joined <- merge(t1, t2, by = \"id\", all.x = TRUE)"
))
#> <p class="kit-hint">以下程式碼依你目前的設定產生,是簡化的示範。</p>
#> <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>
#> <div class="kit-code-head">
#> <strong>base R 版</strong>
#> <button type="button" class="btn btn-sm btn-outline-secondary kit-copy">複製</button>
#> </div>
#> <pre><code>joined <- merge(t1, t2, by = "id", all.x = TRUE)</code></pre>
kit_code_blocks(c("kits 版" = "fit <- kits::kits_calibrate(resp)"))
#> <p class="kit-hint">以下程式碼依你目前的設定產生,是簡化的示範。</p>
#> <div class="kit-code-head">
#> <strong>kits 版</strong>
#> <button type="button" class="btn btn-sm btn-outline-secondary kit-copy">複製</button>
#> </div>
#> <pre><code>fit <- kits::kits_calibrate(resp)</code></pre>