Skip to content

Commit 464c8f9

Browse files
committed
Protect against missing package
1 parent c85bdf2 commit 464c8f9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vignettes/markdown-html-tables.qmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ your_table_function <- function(data, markdown_cols = NULL, quarto = TRUE) {
273273
Here is a more complex example that combines all these features to create a complete HTML table with Markdown content:
274274

275275
```{r}
276+
#| eval: !expr requireNamespace("kableExtra", quietly = TRUE)
276277
library(kableExtra)
277278
278279
# Create a data frame with different types of content
@@ -319,6 +320,7 @@ The **gt** package provides a way to create tables with rich formatting.
319320
Here is the same table example as above, using **gt** with **quarto** R package functions. `fmt_passthrough()` is used to allow raw HTML content in the table cells, and `escape = FALSE` is set to avoid escaping the HTML content:
320321

321322
```{r}
323+
#| eval: !expr requireNamespace("gt", quietly = TRUE)
322324
library(gt)
323325
gt(complex_table) |>
324326
fmt_passthrough(columns = "Example", escape = FALSE)
@@ -329,6 +331,7 @@ Here is the example with built-in support for Markdown content in **gt**:
329331

330332
```{r}
331333
#| warning: false
334+
#| eval: !expr requireNamespace("gt", quietly = TRUE)
332335
data.frame(
333336
Feature = c("Formatting", "Math", "References", "Media"),
334337
Example = c(
@@ -358,6 +361,7 @@ From the **tinytable** package website (<https://vincentarelbundock.github.io/ti
358361
By default, `tinytable` deactivates Quarto HTML table processing. This is a design choice so that **tinytable** formatting is not affected by Quarto's HTML table processing. So, our previous table would look like this:
359362

360363
```{r}
364+
#| eval: !expr requireNamespace("tinytable", quietly = TRUE)
361365
library(tinytable)
362366
363367
tt(complex_table)
@@ -368,6 +372,7 @@ Note that the display value for the video shortcode is used, as the shortcode is
368372
Quarto HTML table processing can be re-enabled in **tinytable**, and in that case, they will handle the `data-qmd` attribute internally, and functions `tbl_qmd_span()` and `tbl_qmd_div()` will not be needed.
369373

370374
```{r}
375+
#| eval: !expr requireNamespace("tinytable", quietly = TRUE)
371376
options(tinytable_quarto_disable_processing = FALSE)
372377
tt(complex_table)
373378
```
@@ -376,12 +381,14 @@ Setting the option will opt-in to Quarto HTML table processing for all tables cr
376381
Let's unset the option:
377382

378383
```{r}
384+
#| eval: !expr requireNamespace("tinytable", quietly = TRUE)
379385
options(tinytable_quarto_disable_processing = NULL)
380386
```
381387

382388
Note that **tinytable** supports `data-qmd` attributes internally, so functions `tbl_qmd_span()` and `tbl_qmd_div()` are not needed when using **tinytable**. You can use `tt()` function directly with Markdown content in the table cells, and mark the cells as using Quarto Markdown processing.
383389

384390
```{r}
391+
#| eval: !expr requireNamespace("tinytable", quietly = TRUE)
385392
data.frame(
386393
Feature = c("Formatting", "Math", "References", "Media"),
387394
Example = c(

0 commit comments

Comments
 (0)