davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
562 stars 81 forks source link

Quarto chunk names which contain spaces cause an error #472

Closed mintzj closed 2 years ago

mintzj commented 2 years ago

In Quarto, chunks which display a flextable generate an error when the name contains a space:

---
title: "Quarto Flextable Demo"
format: docx
editor: source
---

## Quarto Demo

```{r Cars Table, `tbl-cap` = "bogus"}

library(flextable)

ft_cars <- flextable(cars)
ft_cars
```

This results in the following error:

processing file: flextable.qmd
  |.......................                                               |  33%
  ordinary text without R code

  |...............................................                       |  67%
label: Cars Table (with options) 
List of 1
 $ tbl-cap: chr "bogus"

Quitting from lines 10-14 (flextable.qmd) 
Error: bkm [Cars Table] should only contain alphanumeric characters, ':', '-' and '_'.

Execution halted

The `tbl-cap` = "bogus" chunk option was necessary to avoid a separate (possibly related) error:

---
title: "Quarto Flextable Demo"
format: docx
editor: source
---

## Quarto Demo

```{r Cars}
library(flextable)

ft_cars <- flextable(cars)
ft_cars
```
processing file: flextable.qmd
  |.......................                                               |  33%
  ordinary text without R code

  |...............................................                       |  67%
label: Cars
Quitting from lines 10-14 (flextable.qmd) 
Error in opts_current_table() : 
  if a label (Cars) is defined, chunk option `tbl-cap` should also be defined.
Calls: .main ... flextable_to_rmd -> knit_to_wml -> opts_current_table

Execution halted

Session info:


> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] flextable_0.8.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3      digest_0.6.29     R6_2.5.1          grid_4.2.1        evaluate_0.16    
 [6] zip_2.2.1         rlang_1.0.5       gdtools_0.2.4     cli_3.3.0         uuid_1.1-0       
[11] data.table_1.14.2 rstudioapi_0.14   xml2_1.3.3        rmarkdown_2.16    tools_4.2.1      
[16] officer_0.4.4     yaml_2.3.5        xfun_0.31         fastmap_1.1.0     compiler_4.2.1   
[21] systemfonts_1.0.4 base64enc_0.1-3   htmltools_0.5.2   knitr_1.40  
davidgohel commented 2 years ago

Hello,

I am not sure that this is a bug. I see that our errors told you exactly what to do, and you understood what was required.

The second is related to quarto usage. Table captions are expected to be defined in Quarto by a pair of value label and tbl-cap. If you only set a label (used as bookmark), caption will be "no caption"... So it tells you that if you want a caption, you should define that caption.

Now, maybe you did not want a caption?

In that case, we should work again and check that if Quarto and if Word and if label does start with tbl but no caption is found, we should raise that error.

From our understanding, Quarto will change/update the way it handles captions and cross-ref, and we are waiting to see what are the changes to then being able to adapt if possible.

Some packages decided/stated it was not their problem, but the rmarkdown/bookdown/quarto issue. We wish now we had made this choice. ;)

davidgohel commented 2 years ago

closing the issue. We assume you did want a caption :)

github-actions[bot] commented 1 year ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.