Skip to content

gt::fmt_markdown renders incorrectly in Quarto document #1985

@GeorgeBatten

Description

@GeorgeBatten

If we assign the value "" (no space) to certain cells in a data frame, gt will correctly display those as blank cells when rendering the table in RStudio, but if rendering in Quarto, those values are considered non-existent, and the remaining values are (erroneously) recycled. The easy fix is to convert those values to " " (with space). I'm not sure if this is really a bug, perhaps an inconsistency; but one that could have large effects on the output. Below is a Quarto document with examples of the issue (gt version 1.0.0, quarto version 1.7.24, R version 4.5.0):

[originally posted here: https://github.com/quarto-dev/quarto-r/issues/231]

---
date: "`r Sys.Date()`"
---

```{r}
#| echo: false
#| warning: false
#| message: false

library(gt)
```

```{r}
#| echo: true

# Output is correct, but `test` is not formatted
data <- mtcars[1:5, ]
data$comment <- c("test", "`test`", "", "test", "")
data |> 
  gt()
```

```{r}
#| echo: true

# "" (no space) in comment treated as non-existent, so vector is (erroneously) recycled
data <- mtcars[1:5, ]
data$comment <- c("test", "`test`", "", "test", "")
data |> 
  gt()|>
  fmt_markdown(columns = comment)
```

```{r}
#| echo: true

# " " (with space) in comment, treated as existing; works properly
data <- mtcars[1:5, ]
data$comment <- c("test", "`test`", " ", "test", " ")
data |> 
  gt()|>
  fmt_markdown(columns = comment)
```

```{r}
#| echo: true

# Another option: NA + sub_missing (but format is different)
data <- mtcars[1:5, ]
data$comment <- c("test", "`test`", NA, "test", NA)
data |> 
  gt()|>
  fmt_markdown(columns = comment) |> 
  sub_missing(columns = comment, missing_text = "")
```

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions