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
4
votes
1 answer

knitr: keep cache when I make small change in chunk

I understandably broke cache when updating a chunk (however the result should be the same, it was cosmetic changes). However, I do not want to run the chunk again because it takes 1 week to run. How can I change the cache so that the new code thinks…
Xu Wang
  • 10,199
  • 6
  • 44
  • 78
4
votes
1 answer

Font Size and Line Spacing R Slidify

I am trying to create my first Slidify presentation. I am relatively new to JS, CSS and HTML5. I am using the following YAML material and R Markdown code. I want to create a simple slide showing that R can be used as a big calculator. My problem is…
Chris
  • 3,401
  • 5
  • 33
  • 42
4
votes
1 answer

knitr, pandoc: embeding SVG directly to HTML document

I am using knitr to generate reports automatically to a mediawiki page. The report output is in HTML via pandoc. But I am having problems uploading the figures to the wiki site. So I figured that I would use the SVG device and include the code in…
Rúnar Berg
  • 4,229
  • 1
  • 22
  • 38
4
votes
1 answer

Strip YAML from child docs in knitr

I am writing a number of related documents in rmarkdown that I will be compiling into a website through jekyll. In the course of doing this, I have run into a problem: Some of the Rmd files I am using call on other Rmd files as child documents.…
Tom
  • 1,221
  • 1
  • 12
  • 13
4
votes
2 answers

get traceback from knitr on error

How do I get better error reporting from knitr? e.g. now knitr quits with: Calls: knit ... lapply -> FUN -> lapply -> FUN -> rename -> When I run the same code interactively R quits with: Calls: getSampleData ... lapply -> FUN -> lapply…
Ido Tamir
  • 3,017
  • 2
  • 19
  • 28
4
votes
1 answer

KnitR , Latex conditional display of Text and Code block

How do i turn on/off display of perticular subsection based on some condition ? for example, i want to display following sub-section only when xyplotFacSpecTotVarTest.pdf exist. How can i do it ? \subsection{Checksum: Factor, Specific, and Total…
Manish
  • 191
  • 2
  • 4
  • 12
4
votes
1 answer

Knitr - stop superscript in R Markdown

I need to stop superscript before comma - , or full stop - .. When converting the Rmd file to HTML knitr makes comma superscripted as well. Example: example.Rmd MyTitle ======================================================== J.Smith^1, K.John^2,…
zx8754
  • 52,746
  • 12
  • 114
  • 209
4
votes
0 answers

Formatting of ggplot2 graphic text font sizes when using knitr

I was under the impression that if I used the tikz device (that I am trying for the first time today) that graphic text would be consistent with the text in the rest of my Latex document (generated using Knitr / RStudio). However, what I am seeing…
user1420372
  • 2,077
  • 3
  • 25
  • 42
4
votes
1 answer

using knitrBootstrap example drop-down styling

In the link below you'll see the current example for cars with a certain drop-down styling. When I produce this same example I get a different style where the drop down boxes extend the width of the content area. Is there something I need to add to…
rrbest
  • 1,619
  • 3
  • 14
  • 22
4
votes
0 answers

Generate multiple plots per chunk using loop and vectorize over chunk options (fig.height)

I am trying to produce multiple plots in one knitr chunk using a loop. This is not so hard, I just need to wrap each plot in a print() statement and knitr automatically generates appropriate filenames, e.g. chunkname1.pdf,…
rjturn
  • 323
  • 2
  • 8
4
votes
0 answers

R: knitrBootstrap in RStudio using YAML front matter

I am attempting to compile a knitr MWE using the knitrBootstrap package. I am using the Ctrl+Shift+K shortcut key in RStudio, which essentially calls the knit function from knitr. Here is the MWE I am trying to compile, which is basically the MWE…
tchakravarty
  • 10,736
  • 12
  • 72
  • 116
4
votes
1 answer

Getting Unicode character in knitr R-figure snippet

Currently I am making my figs using "unprincipled" (opportunistic) way to get Unicode characters right. For example: <>= pdf('figs/figA.pdf', h=6, w=6, encoding='CP1250') plot(x, y, xlab='rečenica') dev.off() @ Now, I wonder how would I…
striatum
  • 1,428
  • 3
  • 14
  • 31
4
votes
1 answer

\Sexpr{} in a .tex file to reference R object

I am using RStudio 0.98.501 and MacTex 2013 to run an analysis and compile a manuscript. In my setup, I use a master.rnw file that defines the LaTeX template. This file inputs a few manuscript .tex files that collaborators contribute to (they…
Eric Green
  • 7,385
  • 11
  • 56
  • 102
4
votes
1 answer

Matrix multiplication in knitr code chunk

When I include an inline code trunk using \Sexpr{}, the matrix multiplication symbole %*% is interpreted as Latex commenting. How to get around this?
Heisenberg
  • 8,386
  • 12
  • 53
  • 102
4
votes
1 answer

How do I include external graphics in my knitr documents?

I have been using knitr in conjunction with my R work. I have some external graphics that I would like to include in my knitr HTML document. I can't seem to find a method to do so. Should I use R Markdown or is there a more knitr-specific manner to…
tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149