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

R - knitr - ShareLatex - install.packages(xyz)

How do I install packages in a ShareLatex knitr file (.Rtex)?? The R code par(mfrow=c(1,1)) install.packages("tree") library(tree) model.tree.simpel <- tree(response~.,data=dat) plot(model.tree.simpel) text(model.tree.simpel) Error…
user3711518
  • 253
  • 1
  • 3
  • 14
4
votes
1 answer

Error: failed to compile tikz to pdf

On my friends Windows pc, then running any type of plots with knitr outputting with dev='tikz' I get an error. It works with dev='pdf'. It does output the file "foo-1.tikz" and this can be compiled fine on its own, however when using knitr…
4
votes
1 answer

How to knit a greek symbol in R-studio to generate a pdf

I am working with R studio markdown and knitr, all together great stuff. I seem not to be able to knit a greek symbol into pdf. Same Rmd file: --- title: "Untitled" author: "Hugo Koopmans" date: "11-01-2015" output: pdf_document --- Test Greek…
Hugo Koopmans
  • 1,349
  • 1
  • 15
  • 27
4
votes
1 answer

R Presentation - reference css template with web link

I am creating an R Presentation, but I cannot find a way to use a css template stored on a website. This works: Title ======================================================== author: Me date: Jan 9, 2015 transition: none css:…
user3874377
  • 255
  • 3
  • 10
4
votes
1 answer

Usage of variables within double curly braces in R/RMarkdown

From this question, I gather that variables of the form {{var}} can be called echos in other programming languages, but I'm at a loss for why they do what they do in R. Namely, I've used them within an RMarkdown template (here, state_template.Rmd)…
mcjudd
  • 1,520
  • 2
  • 18
  • 33
4
votes
1 answer

using knit on markdown file but ignoring a chunk of code - sourcing knitr files

This is similar to How to source R Markdown file like `source('myfile.r')`? with the following difference: I want my markdown file to generate an R script for future sourcing. The previous question was interested in directly sourcing the markdown…
bmayer
  • 426
  • 3
  • 9
4
votes
1 answer

Insert output of R code into an Rnw file

I regularly embed R code into Rnw files and use knitr to convert the Rnw file to a tex file and then pdf. The upside of this approach is that is increases reproducibility. The downside is that it interrupts the flow of the writing process. For…
luciano
  • 13,158
  • 36
  • 90
  • 130
4
votes
1 answer

Specify docx layout in markdown

I am using r markdown to produce word documents of the output of my code. I was wondering if there is a way that i can specify that the pages are landscape with narrow margins (approx 1.75) with everything formatted from the center of the page with…
4
votes
0 answers

tikz stops drawing into pdf after 20 line segments in plot generated through knitr tikzDevice

Problem If I try to draw a curve generated through knitr using tikzDevice into .pdf only 20 line segments of that curve are drawn and TeXstudio, through which I do it, just leaves message running command…
VaNa
  • 311
  • 4
  • 17
4
votes
1 answer

Knitr & Beamer with Overlays in Figure

I am creating a beamer presentation in which I have a figure displaying several time series together with a legend (say 10 series for 10 countries). I would like to know if there is a reasonably simple way to dynamically add the series within…
PatrickT
  • 10,037
  • 9
  • 76
  • 111
4
votes
1 answer

RStudio, Packrat and Knitr

I'm working in RStudio. I first created a knitr file in a project, and compiling the pdf worked flawlessly. Then, while I was working in different files, I activated packrat for the project. (And later on deactivated it again) Now, when I try to…
FooBar
  • 15,724
  • 19
  • 82
  • 171
4
votes
2 answers

set fig.cap to options$label

How can I programmatically set a figure caption in a knitr hook? I'd like to set the figure caption, if not explicitly defined, to the chunk label. I've read the knitr docs on options, options, and hooks, and though I think I understand the…
r2evans
  • 141,215
  • 6
  • 77
  • 149
4
votes
2 answers

Hyperlinking within an HTML Presentation using R Markdown

I hope I've tagged this correctly - I'd like to create an HTML presentation using Markdown in R Studio. What I'd like to do is to create hyperlinks that will jump to a specified page when clicked versus the straight linear progression of most…
GregRousell
  • 997
  • 2
  • 13
  • 23
4
votes
1 answer

devtools::build_vignettes yields "Error : invalid version specification 'pandoc.exe 1.13.1'

After upgrading R to 3.1.2 and updating all packages I can no longer build vignettes. devtools::build_vignettes(shdoe) The output is as follows: Building shdoe vignettes Error : invalid version specification 'pandoc.exe 1.13.1' Warning in…
SaschaH
  • 351
  • 3
  • 10
4
votes
2 answers

Chunk output without knitrout and verbatim environment

<>= x <- "\\includegraphics[width=\\maxwidth]{figure/Kompetenz1.pdf}" cat(x) @ If I run this r code in my .Rnw file I will get the following output in my .tex…
Mimi Tator
  • 51
  • 2