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

Include tab.cap in eval.after and other chunk options (port to knitr) #2305

Closed
3 tasks done
rikudoukarthik opened this issue Nov 1, 2023 · 2 comments
Closed
3 tasks done
Labels
question Questions (which should belong to forums instead of Github)

Comments

@rikudoukarthik
Copy link

Tables are an important part of documents generated using R markdown. Aside from the base kable, alternatives to creating tables like flextable recommend using tab.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 as glue::glue("This is my caption, and {value1} is a value") for the fig.cap chunk option (after having set eval.after="fig.cap", which is now the default), this is currently not possible for tables because tab.cap is not an option in knitr but from officer.

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

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included 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').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@yihui
Copy link
Owner

yihui commented Nov 1, 2023

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'))

@yihui yihui added the question Questions (which should belong to forums instead of Github) label Nov 1, 2023
@yihui yihui closed this as completed Dec 5, 2023
Copy link

github-actions bot commented Jun 5, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Questions (which should belong to forums instead of Github)
Projects
None yet
Development

No branches or pull requests

2 participants