3

Is it possible to create a custom markdown block within a R function?

Background: I have a custom function which renders a table in a very custom format. At the end of the table I would love to append a standardized text, such as "Table 1: title of my amazing table" in the format my-format. my-format refers to a custom style from a reference_docx. It generates a word document. So in markdown I would write:

```{r}
ft <- flextable(...)
ft # print out flextable
```

:::{custom-style="my-format"}
Table 1: title of my amazing table
:::

Instead I would like to write:

```{r, results='asis'}
ft
cat(paste(':::{custom-style="my-format"}',
    'Table 1: title of my amazing table',
    ':::', '', sep="\n"))
```

However, it does not work as intended. It does not print my flextable anymore. Since this code is inside a function I can't make two r blocks out of it.

Phil
  • 7,287
  • 3
  • 36
  • 66
boraas
  • 929
  • 1
  • 10
  • 24
  • Couldn't you print the markdown table caption outside of the code block and then modify the style `my-format` so that the caption appeared just below the table (e.g., by removing space between lines in the Word style)? – mikebader Oct 14 '22 at 02:07

0 Answers0