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

Lists of data frames do not render as Markdown tables (md_table_parser) #882

Open
math-mcshane opened this issue Jan 12, 2025 · 6 comments

Comments

@math-mcshane
Copy link

math-mcshane commented Jan 12, 2025

Describe the bug
Lists of tables no longer/don't render inside of Quarto -- e.g., Markdown tables

To Reproduce
This Quarto document will fail to render to HTML or markdown. It will succeed when rendering to PDF. And, within-RStudio table-rendering will use the Markdown version, so you can run this code chunk when format: pdf (or any format) and it will, of course, also fail.

---
format: html
---

```{r}
list(data.frame(a = 1:2), data.frame(b = 1:3)) |> 
  knitr::kable() |>
  kableExtra::kable_styling()
```

It looks like an issue inside of kableExtra:::md_table_parser
image

I seem to recall this working before, but have run into this error a couple of times. My guess is that this stopped working when issue #821 was fixed (but I'm not sure).

@dmurdoch
Copy link
Collaborator

This is really not a kableExtra bug, it's a bug in knitr, or Quarto, or RStudio.

The problem is that calling kable() on a list of dataframes calls the knitr::kables() function, and it defaults to format="pipe". So one workaround is to specify the format, i.e. use

list(data.frame(a = 1:2), data.frame(b = 1:3)) |> 
  knitr::kable(format = "html") |>
  kableExtra::kable_styling()

Another workaround is to use kableExtra::kbl() instead of knitr::kable(), because it is better at figuring out the format automatically.

I suspect there's another workaround: don't use RStudio for this. A very similar document using R Markdown instead of Quarto works find if you call it with rmarkdown::render(), but fails if you try to render it by clicking knit in RStudio. I can't tell you if something similar is possible with Quarto, because I never use it.

@dmurdoch
Copy link
Collaborator

See #884 for the R Markdown version.

@math-mcshane
Copy link
Author

Hi, actually this is certainly a kableExtra issue. The kableExtra:::md_table_parser internal function is at issue. I just happened to notice it when using RStudio; but it's a problem when producing a markdown table.

CC @haozhu233

@dmurdoch
Copy link
Collaborator

The problem is that kableExtra doesn't fully support pipe format, but that's what your code produces. kableExtra sometimes tries to handle pipe format, but the support is limited and (as far as I know) undocumented.

@math-mcshane
Copy link
Author

The problem is that kableExtra doesn't fully support pipe format, but that's what your code produces. kableExtra sometimes tries to handle pipe format, but the support is limited and (as far as I know) undocumented.

Sounds like an issue that should be re-opened then

@haozhu233
Copy link
Owner

Yeah, as @dmurdoch mentioned, the support on the pipe markdown tables is very limited. Previously, my rule of thumb was that it should try to return as is, or at least should not trigger an error. I will take a look at this.

@haozhu233 haozhu233 reopened this Jan 20, 2025
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

3 participants