You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firstly, apologies for the huge delay in responding---this is following on from #2305 which got locked after inactivity.
While @yihui showed how eval.after = "tab.cap" can be included in the knitr::opts_knit$set() call, the issue is still unresolved because the tab.cap is not functioning as expected. Please see the small reprex below (add a single ` to chunk open and close calls).
---
title: "Test"
output:
bookdown::word_document2:
editor_options:
chunk_output_type: console
---
```{r, echo=FALSE}
library(glue)
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
knitr::opts_knit$set(eval.after = "tab.cap")
# function to add commas to big numbers in one go
good_num <- function(number) {
if (number < 10) {
xfun::numbers_to_words(number)
} else {
format(number, big.mark = ",", scientific = FALSE)
}
}
cap_x <- good_num(12345)
```
```{r, eval.after = "tab.cap", tab.cap=glue("This is my caption; neither {cap_x} or {cap_y} appears.")}
library(tidyverse)
library(flextable)
cap_y <- good_num(45678)
iris %>%
slice(1:10) %>%
flextable()
```
Ideally, assuming fig.cap behaviour, the caption for the above table should read "This is my caption; neither 12,345 or 45,678 appears.", but instead I get this:
Why is tab.cap not behaving as fig.cap does?
The text was updated successfully, but these errors were encountered:
That's because fig.cap is needed only after a chunk has finished evaluation. Generating the figure is done after a chunk's evaluation is done. However, for the table case here, it's different: the table caption is needed (by flextable()) in the middle of the chunk evaluation.
Interesting, I didn't consider that! So the eval.after option doesn't work for flextable()?
Also, even if the table caption is evaluated in the middle of chunk evaluation, cap_x is already assigned in the previous chunk, so how come that doesn't appear either?
Firstly, apologies for the huge delay in responding---this is following on from #2305 which got locked after inactivity.
While @yihui showed how
eval.after = "tab.cap"
can be included in theknitr::opts_knit$set()
call, the issue is still unresolved because thetab.cap
is not functioning as expected. Please see the small reprex below (add a single ` to chunk open and close calls).Ideally, assuming
fig.cap
behaviour, the caption for the above table should read "This is my caption; neither 12,345 or 45,678 appears.", but instead I get this:Why is
tab.cap
not behaving asfig.cap
does?The text was updated successfully, but these errors were encountered: