Skip to content

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

@cderv

Description

@cderv

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions