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

How to best generate multiple HTML files from RMarkdown based on one dataset?

I have an RMarkdown report that is very useful and has grown to be several pages long with all the figures and tables in the HTML file. It uses the same dataset for all the figures and tables. What I would like to do is to keep generating this large…
variable
  • 1,013
  • 1
  • 12
  • 29
4
votes
2 answers

Automate RStudio processed RMarkdown?

I have an RMarkdown file that I use to generate a nice HTML report. The problem is, I want to be able to automate it so that it can run on a headless server. As such there will be nobody there to start Rstudio and press the 'knithtml' button and it…
variable
  • 1,013
  • 1
  • 12
  • 29
4
votes
1 answer

How to write an article with an abstract referencing data that has not yet been calculated?

UPDATE: Seems like my question is actually a very near duplicate of this question and according to that thread, there is currently no "easy" solution. However, that question is over a year old now, and the time may have changed (one can hope!). My…
dsz
  • 4,542
  • 39
  • 35
4
votes
3 answers

Replace the automatic numbering of captions inrmarkdown / knitr / pdf

I am generating a PDF document with Rmarkdown, within which I want to manually define figure numbers. Below is an example of a chunk: ```{r chunk26, fig.cap = "Fig. 5.3 My figure caption"} plot(1, 1) ``` I use a special numbering to follow the…
Boris Leroy
  • 460
  • 4
  • 14
4
votes
3 answers

Reuse graphics device in subsequent code block

The following R-Markdown code doesn’t work with Knitr: Create a bimodal toy distribution. ```{r} a = c(rnorm(100, 5, 2), rnorm(100, 15, 3)) ``` Set up the graphics device. ```{r fig.show='hide'} plot(0, type = 'n', xlim = c(0, 20), ylim = c(0,…
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
4
votes
2 answers

How do I make plots appear in a knitr vignette using dev.new()?

My package produces a number of graphs, often more than one at once. Using x11 or windows devices there is no problem, knitr builds the vignette with images included. However a requirement of submission to the CRAN repository is the use of dev.new…
Tom C
  • 146
  • 5
4
votes
1 answer

knitr::spin Prevent all chunks for being executed

I'd like to document some R functions (not scripts) as html pages using spin(). I thought of something like: #' Test of rmarkdown wit spin() for an html documented function #' ======================================================= #+…
user2955884
  • 405
  • 2
  • 11
4
votes
1 answer

Is it possible to include ggvis() output in Rstudio *.Rpres documents?

The latest version of rstudio includes the ability to generate HTML5 slide decks using some background magic similar to slidify. However, if I include Slide With Plot ======================================================== ```{r,…
Michael Williams
  • 1,125
  • 2
  • 9
  • 13
4
votes
2 answers

Knitting RMarkdown with ggvis to Word

When I try to knit a RMarkdown document with ggvis plots to Word, I get the following message from Rstudio. Error: Functions that produce HTML output found in document targeting docx output. Please change the output type of this document to…
kevinykuo
  • 4,600
  • 5
  • 23
  • 31
4
votes
2 answers

Have Emacs to automatically latex your Rnw file after knitting

I would like to start a LaTeX after knitting an .Rnw file. The meta code shoudl be something like: (defun knit () (interactive) (setq rproc (ess-get-process ess-current-process-name)) (setq c "knit('foo.rnw')\n") (process-send-string rproc…
antonio
  • 10,629
  • 13
  • 68
  • 136
4
votes
1 answer

How do I remove the _printed_ output warnings using ggplot2 with knitr

GGplot2 prints out a warning when using scale_colour_gradient twice in a plot, which I cannot suppress in knitr. Here is a screenshot of my browser after knitting an RHTML file: I need to colour gradients, one for the line (cheap / dear of yield…
Thomas Browne
  • 23,824
  • 32
  • 78
  • 121
4
votes
1 answer

Controlling the size and number of graphs per pdf page generated by ggplot loop in R markdown

I would like to generate a pdf document, using R markdown, to display a series of plots made using ggplot in a for loop. Is it possible to control number of plots on each page so there is, for example, a 2 X 2 grid of plots per page? I'd like to…
Damian
  • 516
  • 1
  • 4
  • 20
4
votes
2 answers

How to deal with double braces in code chunk?

I am writing Rmd files introducing the whisker package. And use slidify to compile it to html slides. Therefore it is inevitable to use {{ and }} in the code. I wrote the following code in the Rmd file: ```{r} tpl <- " Against:
TomHall
  • 286
  • 3
  • 15
4
votes
0 answers

How do I debug errors in pandoc conversion of Latex equations to MS Word?

I am using pandoc through RStudio to convert .Rmd files to docx format. I am able to insert Latex equations and have them appear in my docx file correctly. However, there are a few errors here and there where equations appear correctly if I paste…
csfowler
  • 428
  • 2
  • 12
4
votes
1 answer

knitr shows comments from library import

I have a small Rnw file. When compiled with knitr, it shows importing comments in the pdf. How do I remove these comments? Here is the file…
highBandWidth
  • 16,751
  • 20
  • 84
  • 131