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 install from github

I'm looking forward to getting my hands on an update of Yihui Xie's knitr package that includes a new chunk option (collapse). I'm trying to install the development version from github but am getting an error. I'm using: install_github("knitr",…
ZRoss
  • 1,437
  • 1
  • 15
  • 32
4
votes
2 answers

How can i add a bibliography with knitr

I am trying to generate a .docx file from rmd with knitr/pandoc within RStudio. But I am receiving the followinfg erroe messge status 83 and I can't solve the status message. Any suggestions or help would be nice. Thank you very much.…
SebastianS
  • 477
  • 7
  • 14
4
votes
1 answer

knitr: how to set keepaspectratio in figure

I have some figures generated by R too tall to fit on the page. I want to include these figures but scale down the figure according to a height restriction. <>= Unfortunately, this squishes the plot…
hatmatrix
  • 42,883
  • 45
  • 137
  • 231
4
votes
1 answer

Passing graphical parameters across chunks in knitr

Can anyone help me in relation to passing (or setting global) par graphical parameters across chunks in knitr. I have a large piece of R code with a loop that generates a plot at each iteration of the loop and prints each plot on the same page of a…
4
votes
3 answers

Add tex distribution to PATH for R studio

I have recently begun using knitr with Rstudio. I ran into the "No tex installation detected. Please install TeX before compiling." error in both my Ubuntu and windows OS's. After some research I was able to amend the issue in Ubuntu by adding the…
Abstracted
  • 390
  • 3
  • 14
4
votes
1 answer

Whitespace around an xtable

I'm trying to insert a small table in a body of text using knitr. The I'm not sure if it's a knitr/sweave problem or with xtable but I get a ton of whitespace around the table. Here is an example of the output with the table set to 5cm: When I…
GregRousell
  • 997
  • 2
  • 13
  • 23
4
votes
1 answer

knitr pandoc: "cannot produce pdf output with pdf writer"

Up front: using pandoc() in knitr, it complains when trying to compile .md or .Rmd into a PDF. I'm streamlining the process for reproducible research, as has been documented in many places. I'm using pandoc and knitr and producing great documents.…
r2evans
  • 141,215
  • 6
  • 77
  • 149
4
votes
0 answers

Styling R output with knitr

I'm generating pdf files from R markdown files (.Rmd). I'd like to style the output with the LaTeX listings package. Is there some way to indicate in the .Rmd file which style to wrap the R output in? For example, the following…
Tyler
  • 9,872
  • 2
  • 33
  • 57
4
votes
1 answer

Print actual P-value only if >0.001

Consider the P-values from these two t-tests set.seed(1) x <- c(rnorm(50,1), rnorm(50, 2)) y <- (c(rep("a", 50), rep("b", 50))) t.test(x ~ y)$p.value [1] 1.776808e-07 set.seed(2) x <- c(rnorm(50), rnorm(50)) y <- (c(rep("a", 50), rep("b",…
luciano
  • 13,158
  • 36
  • 90
  • 130
4
votes
3 answers

In R and knitr, how do I plot INLA results?

I'm trying to inlude some INLA code in my knitr document and print plots: Using a trivial example \documentclass{article} \begin{document} <>= library("INLA") n = 100 z = runif(n) eta = 1 + 0.1*z N = 20 p = exp(eta)/(1+exp(eta)) y =…
radek
  • 7,240
  • 8
  • 58
  • 83
4
votes
2 answers

R: t.test output for LaTex

I wonder if there is any function to redirect the output of t.test to LaTeX. Some thing like this library(xtable) xtable(t.test(extra ~ group, data = sleep))
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
4
votes
2 answers

Unicode characters in plots to use in dynamic reports using R, Sweave and knitr

I have a problem properly displaying fonts in plots generated by ggplot2 in LaTeX reports generated by R studio in Sweave using knitr. At first I was not able to properly generate pdfs with polish fonts but that problem was tackled in this…
WojciechF
  • 370
  • 2
  • 14
4
votes
1 answer

missing chunk names in knitr tangled R code

When using Stangle on a Sweave document, the output includes a comment that gives the chunk name. This is incredibly useful in a teaching setting to orient students in the code as they cut-and-paste. However, when I use knitr to generate the .R…
seandavi
  • 2,818
  • 4
  • 25
  • 52
4
votes
1 answer

Add div around all text in knitr

I am trying to add the following div and class to an entire Rmd file in knitr:
I have created the container class using css as follows: .container { box-shadow: 10px 10px 5px #888888; width: 70%; margin:…
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
4
votes
2 answers

R Run knitr from a batch-file (windows)

I run some automatic reports each day with batch-files on my windows-computer. But how do I do this with a .rmd file and generate the html-output? So, this works for me using a batchfile with a normal .R file: "C:\R\R-3.0.1\bin\x64\Rscript.exe"…
Thorst
  • 1,590
  • 1
  • 21
  • 35