28.31 Knitr Options
REVIEW We have explored only some of the functionality of knitr (Xie 2023) and LaTeX. Together there is virtually nothing they can not do—being programming languages anything that can be done, can be done using these tools.
As a summary below we list the common knitr (Xie 2023)
options. The options are added to the chunk start line or else we can
set the options using
opts_chunk\$set(). The arguments to
the function can be any number of named options with their values. For
# Set global defaults for knitr options. $set(size="footnotesize", message=FALSE, tidy=FALSE)opts_chunk
Once this is run, the options remain in force as the default values
until they are again changed using
opts_chunk\$set(). They can be overriden per chunk in the
="#F7F7F7" # The background colour of the code chunks. background="cache/" # cache.path=NA # Suppresses "`## `" in R output. comment=FALSE # Do not show R commands---just the output. echo=3:5 # Only echo lines 3 to 5 of the chunk. echo=FALSE # Do not run the R code---its just for display. eval=2:4 # Only evaluate lines 2 to 4 of the chunk. eval="center" # fig.align="Caption..." # fig.cap="high" # fig.keep="fig:" # Prefix for the label assigned to the figure. fig.lp="figures/plot" # fig.path="Short cap." # For the table of figures in the contents. fig.scap="animate" # Collect figures into an animation. fig.show="hold" # fig.show=9 # Height of generated figure. fig.height=12 # Width of generated figure. fig.width=FALSE # Include code but not output/picture. include=FALSE # Do not display messages from the commands. message=".6\\textheight" # Figure takes up 60% of the page height. out.height=".8\\textwidth" # Figure takes up 80% of the page width. out.width="markup" # The output from commands will be formatted. results="hide" # Do not show output from commands. results="asis" # Retain R command output as LaTeX code. results="footnotesize" # Useful for Beamer slides. size=FALSE # Retain my own formatting used in the R code.tidy
New options defined in this Chapter and used in this book:
=4 # Number of lines of R output to show. out.lines=80 # Truncate R output lines beyond this. out.truncate=NULL # Number of lines of output at top to show. src.bot=NULL # Number of lines of output at bottom to show.src.top
———. 2023. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.
Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0