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

Root directory for python chunk in knitr?

I hope this isn't as simple as it feels. I've got a basic directory set up of: root --> Paper --> Code for a paper I'm writing. I want to call a Python script in the Code directory from my knitr document in the Paper directory (something…
Winawer
  • 671
  • 8
  • 26
4
votes
3 answers

knitr compile problems with RStudio (windows)

i have a knitr based Rnw file that is compiling to pdf perfectly fine in RStudio on mac (v0.97.316) and knitr (v1.1) but in a windows enviornment (same versions) i get a compilation error. I've checked the options in RStudio in both environments and…
Andy Judson
  • 441
  • 1
  • 5
  • 8
4
votes
1 answer

ggplot2: Exclude legend from aspect ratio

I use ggplot2 and knitr to publish scatterplots with a right-hand-side legend. The legend is included in the aspect ratio and therefore breaks the "squareness" of the plots, as shown in the default themes. When the legend text becomes a bit longer…
Fr.
  • 2,865
  • 2
  • 24
  • 44
4
votes
1 answer

knit command doesn't work whereas knit HTML button does

I have a Rmd file that uses some of the saved Rdata in the working directory and displays them, pretty simple. I even have cache=FALSE. When I click the kintHTML button, I get the html page. When I go to the Rstudio console and type…
4
votes
1 answer

How to use a "R-generated" plot as a semi-transparent background in an HTML5 slide made by knitr?

I want to add a plot to my first page of the (HTML5) slide. Can I achieve this in a dynamically way? Say, the background image will be generated by R code, rather than insert a semi-transparent PNG image. Thank you. Update: What I want is
Ziyuan
  • 4,215
  • 6
  • 48
  • 77
4
votes
2 answers

Multiple figures with rhtml and knitr

I have an Rhtml file from which I source a R file. In this R file I am doing some plots. p=ggplot(data) p+geom_line() Now, I can produce one plot after the other and when doing knit(".Rhtml") then I get on figure after the other. But I would like…
steffi
  • 513
  • 4
  • 15
4
votes
1 answer

knitr: starting a fresh R session to clear RAM

I sometimes work with lots of objects and it would be nice to have a fresh start because of memory issues between chunks. Consider the following example: warning: I have 8GB of RAM. If you don't have much, this might eat it all up. <>= a <-…
Xu Wang
  • 10,199
  • 6
  • 44
  • 78
4
votes
3 answers

How to customize a css for markdown + knitr in Rstudio?

I want to change the default style sheet for the KnitHTML function in RStudio 0.96.331. I follow the instructions in this post. First I copy past the original markdown.css from here . As a test I change the first few lines from: body, td…
Fred
  • 1,833
  • 3
  • 24
  • 29
4
votes
1 answer

Knitr chunk is importing a subset of the records from *.csv as same code in R

Rstudio version 0.96.331 and knitr version 0.8 I thought my problem had been solved with update of RStudio and libraries... however: The following run in R gives me 940 unique Table.ID values. Run in a knitr chunk I get 228 unique values and the…
Michael Williams
  • 1,125
  • 2
  • 9
  • 13
4
votes
1 answer

Knit2html not replicating functionality of Knit HTML button in R Studio

I'm trying to write a Bash script in Ubuntu 10.04 that opens a Python file which exports a CSV, and then runs the following Rscript with the goal of exporting a HTML with plots from…
4
votes
1 answer

How do I get RStudio to publish R-markdown to the rpubs.org site?

According to a response from the RStudio team, the "standard" solution would be to follow the instructions for "Using R Markdown with RStudio", and notice the button on the third screenshot with the "Publish" button. A wonderfully simple solution…
Paul 'Joey' McMurdie
  • 7,295
  • 5
  • 37
  • 41
4
votes
2 answers

Plots are empty using Sweave and Latex

I want to make a report with the graphics I obtain with R. Here I show you both images produced with site_rose(site_ref) and site_time_series(site_ref) I designed. But after running sweave('Profile.Rnw') and getting Profile.tex I obtain…
JPV
  • 1,079
  • 1
  • 18
  • 44
3
votes
1 answer

Way to automatically escape characters ('_','\' etc) using knitr

I m using Rstudio under Win7. Is there a way that knitr automatically escape a character? Please see below for a simpler…
Stat-R
  • 5,040
  • 8
  • 42
  • 68
3
votes
2 answers

Including several tables in tex format in my main document

Is there a way to generate tables in tex format in R and then call them in my *.rnw file I have to geenerate a lot of tables using some userdefined function and then use them in my latex file through sweave/knitr. Here is a simplified example to…
Stat-R
  • 5,040
  • 8
  • 42
  • 68
3
votes
1 answer

Defining controlling parameters for graphs globally in knitr

To control the size of graph in knitr I use the following code \begin{figure}[H] \centering << label = Plot1, fig.width=5, fig.height=5, out.width=.7\linewidth, fig.keep = all>>= ... @ \caption{Plot} \label{fig:figPlot1} \end{figure} I…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309