Skip to content

Formatting small numbers, inside a gt in docx output fails #6274

Closed
@mattansb

Description

@mattansb

Bug description

I don't know why, but this super specific combination of conditions results in the error:

Quitting from lines 14-17 [unnamed-chunk-2] (tests.qmd)
Error in `read_xml.raw()`:
! StartTag: invalid element name [68]
Backtrace:
  1. global .main()
 74. xml2:::as_xml_document.character(.)
 75. xml2:::read_xml.raw(...)
  1. Format a column using a specific function in gt() |> fmt(). For example:
  • scales::label_pvalue()
  • insight::format_p
  1. Have a data frame with a small number - how small? Smaller than smallest formatted output by these functions.
    For example, smaller than 0.001 (both of these functions by default show <0.001 for any p-value smaller than 0.001).
  2. Output to docx

Steps to reproduce

---
format: docx
---

```{r}
library(gt)
library(scales)

aov_table <- data.frame(asdqwezxc = c(0.0009))
```


```{r}
fmt(gt(aov_table), fns = label_pvalue(0.001))
```

Expected behavior

A docx with a gt output with a formatted column.

Actual behavior

Quitting from lines 14-17 [unnamed-chunk-2] (tests.qmd)
Error in `read_xml.raw()`:
! StartTag: invalid element name [68]
Backtrace:
  1. global .main()
 74. xml2:::as_xml_document.character(.)
 75. xml2:::read_xml.raw(...)
Execution halted

Your environment

  • IDE: RStudio 2023.06.1
  • OS: Win11

Quarto check output

[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.5: OK
      Dart Sass version 1.55.0: OK
      Deno version 1.33.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.236
      Path: C:\Users\user\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....(None)

      Unable to locate an installed version of Python 3.
      Install Python 3 from https://www.python.org/downloads/

[>] Checking R installation...........OK
      Version: 4.3.1
      Path: C:/PROGRA~1/R/R-43~1.1
      LibPaths:
        - C:/Users/user/AppData/Local/R/win-library/4.3
        - C:/Program Files/R/R-4.3.1/library
      knitr: 1.43
      rmarkdown: 2.23

[>] Checking Knitr engine render......OK

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions