yihui/printr

Offer a way to use paged_table() feature from R Markdown within Quarto

cderv opened this issue · 1 comments

cderv commented

See this discussion: quarto-dev/quarto-cli#933 (reply in thread)

df_print is not a Quarto feature. But while writing an example on how it would work, I am wondering if we should not adapa printr package to allow opt-in some mechanism for chunk.

Currently printr only modifies by default the method knit_print but we could offer other mechanism.

For example this is an example of creating a df_print chunk option

```{r}
kable_print <- function(x, options) {
  knitr::asis_output(
    paste(c("", "", knitr::kable(x)), collapse = "\n")
  )
}

paged_print <- function(x, options) {
  knitr::asis_output(
    rmarkdown:::paged_table_html(x, options = attr(
      x,
      "options"
    )),
    meta = list(dependencies = rmarkdown::html_dependency_pagedtable())
  )
}

knitr::opts_hooks$set(df_print = function(options) {
  if (options$df_print == "paged") {
    options$render = paged_print
  } else if (options$df_print == "kable") {
    options$render = kable_print
  }
  options
})

```

```{r, df_print = "paged"}
iris
```

```{r, df_print = "kable"}
head(iris)
```

```{r}
head(iris)
```

This works well within Quarto. As other option described in quarto-dev/quarto-cli#933 (reply in thread)

This is to share some thoughts and idea. I think there is some useful change we could do.

Anyway, main addition in printr would be a knit_print method for paged_df maybe.

yihui commented

Anyway, main addition in printr would be a knit_print method for paged_df maybe.

That sounds relatively simple to do, and I'm totally okay with it.

I'm not sure where to support the chunk option df_print = "paged" or "kable" (knitr or printr? I don't have an opinion for now).