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 Do I Get Back to a Simple Markdown Format for Image Captions Using RStudio (knitr?)?

I just updated several R packages and it seems to have introduced breaking changes in the production of markdown interim output from Rmd documents in RStudio. Assuming knitr is still used by RStudio to generate md from Rmd on the way to producing…
psychemedia
  • 5,690
  • 7
  • 52
  • 84
4
votes
2 answers

How to extract the content of SQL-Files using R?

I have of folder/directory of one of my colleagues full of sqlstatements. The folder is updated by him daily as well. I would like to document these sqlstatements for futures colleagues. However, I'm looking for a way to "automate" that process. I…
Mamba
  • 1,183
  • 2
  • 13
  • 33
4
votes
1 answer

Paths in ssh versus Rstudio server for pandoc and knitr

I am running a Rstudio AWS instance using the premade AMI (http://www.louisaslett.com/RStudio_AMI/). Using this i am able to boot into rstudio server. I can create a default .Rmd file and knit without problem. I get the normal message at the end…
bw4sz
  • 2,237
  • 2
  • 29
  • 53
4
votes
1 answer

rmarkdown ioslides: output file in a folder and dependencies in other

I'm trying to embbed an ioslides rmarkdown presentation in a jekyll website, so I need to render the .Rmd file to a _posts folder in the main directory of my website. But, images can't be placed in this folder, so I'm placing then in a images…
Daniel Falbel
  • 1,721
  • 1
  • 21
  • 41
4
votes
1 answer

how to add grid to table with pander?

I am working with R, knitr and pander, and I can't find the option that would allow me to print a grid on a table with pander. I tried : pander(tableToPrint, style='grid') but it doesn't do anything, neither with this option or with 'multiline',…
Malta
  • 1,883
  • 3
  • 17
  • 30
4
votes
1 answer

print data.frame column and color by type

In my Knitted document, I am trying to print a dataframe's column. Just to aid the visualization, I would like to change the output color to change based on the value of another column. I have a simple example as follows. date_vector <- rep(NA,…
tallharish
  • 242
  • 1
  • 12
4
votes
1 answer

Why does 2nd ggplot not appear using knitr and grid?

I am trying to create a document using knitr that includes ggplot2 plots modified using grid. In the example below, there should be 2 plots both using the diamonds dataset included in ggplot2: the first one shows cut vs. color and the second shows…
CephBirk
  • 6,422
  • 5
  • 56
  • 74
4
votes
1 answer

Knitr: Trailing zeros on inline text

I am currently having trouble achieving the desired rounding of numbers using knitr. The issue occurs with numbers that would end with a zero on the final rounded digit. An example of this is 14.04, which I want to be rounded at 1 decimal place to…
pmgurman
  • 41
  • 2
4
votes
0 answers

R Markdown file looses encoding information after being knit into HTML/PDF

So far I was using combination of R + Rstudio + knit (to mostly HTML) in english so perhaps that's why I never stumbled on this issue. Recently, however, I started writing a doc in polish and noted that whether I knit to HTML or PDF, the text loses…
nimdil
  • 1,361
  • 10
  • 20
4
votes
1 answer

knitr / jekyll / servr::jekyll images are enormous or not good resolution

This is my first post to SO and I'm hoping my question is specific enough. I have written a blog post using servr::jekyll() [Thanks, Yihui], but the images don't size up correctly on the blog post - they are enormous! When I don't specify the image…
Nick Tierney
  • 192
  • 1
  • 8
4
votes
0 answers

Gnu make on windows alters R search path

I am writing a document with knitr and latex on linux. I made a small makefile to automate the build. It works perfectly fine on linux, but it is problematic on windows. Issuing make I…
Sam De Meyer
  • 2,031
  • 1
  • 25
  • 32
4
votes
1 answer

How does pandoc parse latex code in a .md file?

I am using Rstudio with knitr/rmarkdown/pandoc/latex to render .Rmd code to pdf. I have been struggling with certain latex code being rendered exactly as expected while very slightly different code ends up not being parsed correctly, which results…
4
votes
2 answers

Save knitr chunk to R file

In knitr there is a read_chunk function which read external code into a chunk. Is it possible to reverse the process. That is, make a function write_chunk() which save the source code in the chunk to an R file? The file name may the same as the…
Relund
  • 611
  • 3
  • 14
4
votes
1 answer

Increment section numbers in PDF output

I'm trying to increment the section headers in my rMarkdown (PDF output) file by 1. Instead of # First resulting in 1 First, I'd like 2 First. I found a way to define the offset in html_output using the following syntax, but it doesn't work for…
Golan Trevize
  • 77
  • 1
  • 7
4
votes
1 answer

Using tikzDevice in lyx doesn't work

I am trying to include a histogram created with qplot(ggplot2) with the code chunk <>= plot(hist.age) @ It works just fine with dev='pdf', but doesn't work with dev='tikz'. The library…
Hengrui Jiang
  • 861
  • 1
  • 10
  • 23