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

NA processing with Quarto doesn't work #263

Closed
cbgoodman opened this issue Jun 4, 2024 · 5 comments
Closed

NA processing with Quarto doesn't work #263

cbgoodman opened this issue Jun 4, 2024 · 5 comments

Comments

@cbgoodman
Copy link

When asking tinytable to process NA's with quarto = TRUE, there's no processing with TeX.

---
title: "testing"
format: pdf
---

```{r}
#| include: false
library(tidyverse)
library(tinytable)

assignments = tribble(
  ~Points,  ~Assignment,
  4 * 10  , "Analytical Assignments",
  0       , "Team Project Part 0 - County Selection",
  10      , "Team Project Part 1 - Summary Background",
  10      , "Team Project Part 2 - SWOT Analysis",
  10      , "Team Project Part 3 - Strategic Direction/Action Plan",
  10      , "Team Project Part 4 - Evaluation Framework",
  10      , "Team Project Part 5 - Plan Presentation",
  20      , "Class participation"
) |>
  mutate(Percent = Points / sum(Points),
         Percent = scales::label_percent(accuracy = 1)(Percent))

assignments_total = tibble(Assignment = "Total",
                            Points = sum(assignments$Points),
                            Percent = NA)

bind_rows(assignments, assignments_total) |>
  na_if(NA) |> 
  select(Assignment, Points, Percent) |> 
  tt(width = c(.5, .125, .125)) |> 
  format_tt(replace = "-", quarto = TRUE) |>
  style_tt(j = 1:3, align = "lcc")

CleanShot 2024-06-04 at 17 51 17@2x

Works fine with HTML (and Quarto processing turned off)

CleanShot 2024-06-04 at 17 51 58@2x

vincentarelbundock added a commit that referenced this issue Jun 5, 2024
@vincentarelbundock
Copy link
Owner

Thanks a lot for the report @cbgoodman . The primary issue should be fixed on Github now.

Unfortunately, investigating this brought to my attention two more issues in dealing with Quarto.

Issue 1: Special characters

When compiling to LaTeX, Quarto will sometimes interpret some Base64 encoded strings as Markdown code. For example, if you call format_tt(replace="-", quarto=TRUE), Quarto will believe that - is the start of a bullet point list, and will insert a \begin{itemize} inside your table. This breaks compilation.

I recommend you use a "non-markdown" character or an empty space when replacing NAs.

See below for an example.

Issue 2: Quarto data processing in LaTeX

I believe that tinytable behaves in the way that Quarto developers suggest, in terms of inserting \QuartoMarkdownBase64{} macros around cell content that should be data processed by Quarto.

This works in HTML but unfortunately not in LaTeX. @andrewheiss once linked to this thread when explaining that the strategy only worked for HTML.

Andrew, do you know if a new workaround was proposed? I see that the original Quarto issue has been closed, but I can't quite figure out what the recommeded strategy is.

Example

---
title: "Citations in tables"
format: 
  pdf:
    keep-tex: true

references:
- type: article-journal
  id: Lovelace1842
  author:
  - family: Lovelace
    given: Augusta Ada
  issued:
    date-parts:
    - - 1842
  title: >-
    Sketch of the analytical engine invented by Charles Babbage, by LF Menabrea, 
    officer of the military engineers, with notes upon the memoir by the translator
  title-short: Molecular structure of nucleic acids
  container-title: Taylor’s Scientific Memoirs
  volume: 3
  page: 666-731
  language: en-GB
---


```{r}
#| message: false
library(tinytable)
x <- data.frame(Thing = 1:2, Citation = c("@Lovelace1842", NA))

tt(x) |> format_tt(replace = " ", quarto = TRUE)
```


```{r}
#| eval: false
tt(x) |> format_tt(replace = "+", quarto = TRUE)
```

@cbgoodman
Copy link
Author

Thanks, @vincentarelbundock! I wish my bug reports had not uncovered fundamental issues with Quarto processing, but this isn't the first time it's happened. 🤷‍♂️

@cbgoodman
Copy link
Author

Oh, right, context. I've been pestering @andrewheiss with Quarto bugs that are really not implemented features (that are also poorly documented) for ages.

@cbgoodman
Copy link
Author

Can confirm the special characters issue is solved. The secondary issue still remains, but I expected that.

@vincentarelbundock
Copy link
Owner

Thanks for confirming. Closing because there is probably nothing I can do to fix the rest here.

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