Closed rikudoukarthik closed 7 months ago
You can set it by yourself via opts_knit$set()
, e.g.,
knitr::opts_knit$set(eval.after = c('tab.cap', 'fig.cap'))
If you want to apply this to all your documents, you can set a global option in your .Rprofile
:
options(knitr.package.eval.after = c('tab.cap', 'fig.cap'))
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.
Tables are an important part of documents generated using R markdown. Aside from the base
kable
, alternatives to creating tables likeflextable
recommend usingtab.cap=""
in the chunk options to define table captions. Very often, one would like to use inline code to generate elements of the caption, particularly since tables are often used to show data summaries. While this is easily done using a regular R string such asglue::glue("This is my caption, and {value1} is a value")
for thefig.cap
chunk option (after having seteval.after="fig.cap"
, which is now the default), this is currently not possible for tables becausetab.cap
is not an option inknitr
but fromofficer
.There have been previous discussions (feature request) on porting this option over to
knitr
, but I don't think it has been prioritised. Given how frequently tables are generated in R markdown, I think it makes sense to allow the captioning for tables to follow the same format as for figures. My current workaround is to create a new initial chunk which creates the required objects, which are then referenced in-line in the subsequent chunks. But this is not very elegant, and it would be great to have caption options for tables and figures to be implemented in the same way.By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.