Questions tagged [knitr]

knitr is an R package for dynamic report generation based on the concept of literate programming.

knitr is an package for dynamic report generation based on the concept of . That is, you can mix text, R code, and its output into a single document.

It combines features of and related R packages like weaver and R2HTML. It has built-in support for cache, graphics via the tikzDevice package, syntax highlighting via the highlight package and code reformatting via the formatR package.

Unlike Sweave, the document format for knitr does not have to be : , , , and are also supported. Both the syntax and the output are customizable via pattern lists and hook functions respectively, for example, it is easy to make use of the listings package to mark up R code and output by setting up a series of output hooks. A rich set of chunk options and package options are documented in the package website. There are also demos showing possible applications of knitr.

Below is a "Hello World" output from knitr taken from the package manual:

knitr hello world example code and output

Repositories

Vignettes

Book

Other resources

Related tags

5297 questions
3
votes
1 answer

Saving graphs in both PDF and PNG format but using PDF files in the final document

I'm using knitr for my analysis. I can save graphs in PDF format with \SweaveOpts{dev=pdf} and in PNG format with \SweaveOpts{dev=png}. I'm interested to save graphs both in PDF and PNG format in one run but to use the PDF in the final documents…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
3
votes
0 answers

knitr multiple plot alignment

Here is a minimal example: \documentclass{article} \begin{document} <>= plot(1,1) plot(2,2) @ \newpage <>= plot(1,1) plot(2,2) @ \end{document} Note the…
Sang
  • 535
  • 5
  • 14
3
votes
1 answer

Adjust spacing between title and subtitle of html_document output from Rmarkdown

I am trying to adjust the vertical spacing between the main title and subtitle for html output from rmarkdown. I've read many questions that address this for pdf output but none of the solutions appear to work for html. YAML looks like…
CAWA
  • 123
  • 10
3
votes
1 answer

Change in chunk message handling in new version of knitr

In previous versions of knitr, I was able to set the chunk option message = FALSE and it would both have the documented feature of preventing messages from going to the text document (markdown in this case) and would also have the undocumented…
3
votes
1 answer

Is there a reason why CSS is not working with ioslides when the runtime is set to "Shiny"?

I'm trying to include an external css sheet including, in particular, an image for the title slide background for an ioslides presentation using some shiny features on some slides, but it seems like no css is being implemented. When I remove…
tenten526
  • 31
  • 1
3
votes
3 answers

RMarkdown Prevent code outputs from breaking across pages

In RMarkdown using the PDF output option, sometimes the outputs of code blocks get split between pages (as shown in sample below. This sometimes yields outputs where just a small section of the output is on one page and the larger section is on…
Alex Essilfie
  • 12,339
  • 9
  • 70
  • 108
3
votes
1 answer

Error with Unicode escape character U+001B knitting .rmd to .pdf

When trying to knit my rmd file, I'm getting this error - ! LaTeX Error: Unicode character ^^[ (U+001B) not set up for use with LaTeX. Error: LaTeX failed to compile Task1-Final.tex. See https://yihui.org/tinytex/r/#debugging for…
3
votes
1 answer

Generate paragraphs inside a loop in Quarto

I want to generate with R / Quarto a Word document (docx) in which, inside an item, I have sub-items created by looping. I’m using R version 4.2.2, R Studio 2022.12.0 Build 353, Quarto 1.2.280 and Ubuntu 20.04. For example, after an introductory…
Antonio
  • 563
  • 1
  • 5
  • 12
3
votes
2 answers

Wrapping A Line Without Spaces In R-Markdown Output

Writing the following R-Markdown chunk at the beginning of an R-Markdown file allows me to wrap a line in R-Markdown PDF output, provided that the R package formatR is installed and the line to wrap has a whitespace character. How do I wrap a line…
Tom Lever
  • 321
  • 3
  • 16
3
votes
1 answer

Is there a way to implement knitr chunk and knit options as a project-wide environment or profile for R Markdown?

I've grown tired of repeating the beginning of R Markdown documents over and over again to set up my preferences for knitting and chunk options. An example: ```{r, include=FALSE} library(tidyverse) knitr::opts_chunk$set(error = FALSE, message =…
3
votes
0 answers

R Markdown stops rendering when encountering a chunk with base R graphics

sessionInfo() R version 4.2.1 (2022-06-23) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Monterey 12.3 Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib locale: [1]…
haymourt
  • 31
  • 2
3
votes
1 answer

In knitr HTML output, include line numbers of R Markdown source code?

Question: Is there an automatic way to add the line numbers of the original R Markdown source code to the formatted code portions of the HTML output produced by knitr? Purpose: My ultimate goal is to be able to quickly move to parts of my source R…
nuthatch
  • 33
  • 5
3
votes
1 answer

RMarkdown: Floating TOC AND TOC at the start of the report

I want to have both: a floating TOC and a TOC at the start of the report (in Rmarkdown). I think it's only possible to have one. Here, I have manually added a TOC. --- title: "Report" author: "Anon" date: '2022-07-20' output: html_document: …
Pss
  • 553
  • 4
  • 12
3
votes
0 answers

Reduce size of HTML file in Rmarkdown with a lot of plotly graphs

I'm trying to create an HTML Rmarkdown that runs many plotly graphs... The issues in the HTML file is too big and can't open it. I found out that I can use "partial_bundle" function to reduce the size of my file. On my home computer it works…
AnonX
  • 167
  • 8
3
votes
1 answer

How to include a multipage PDF in RMarkdown with dynamic paths?

I was able to figure out how to include a multi-page PDF document in my RMarkdown output using "\includepdf", but I need to be able to change the path to different PDFs based on conditions in the data. I'd like to be able to call the PDF file path…
Laura T.
  • 33
  • 3
1 2 3
99
100