Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cderv opened this issue May 20, 2022 · 1 comment
Open

Comments

@cderv
Copy link
Contributor

cderv commented May 20, 2022

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
Copy link
Owner

yihui commented May 23, 2022

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants