Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A general-purpose tool for dynamic report generation in R

NotificationsYou must be signed in to change notification settings

yihui/knitr

Repository files navigation

R-CMD-checkCheck knitr examplesCodecov test coverageCRAN release

The R packageknitr is a general-purpose literate programming engine,with lightweight API's designed to give users full control of the outputwithout heavy coding work. It combines many features into one package withslight tweaks motivated from my everyday use of Sweave. See the packagehomepage for details and examples. SeeFAQ's for a list offrequently asked questions (including where to ask questions).

Installation

You can install the stable version onCRAN:

install.packages('knitr')

You can also install the development version (hourly build) fromhttps://yihui.r-universe.dev:

options(repos= c(yihui='https://yihui.r-universe.dev',CRAN='https://cloud.r-project.org'))install.packages('knitr')

Motivation

While Sweave and related add-on packages likecacheSweave andpgfSweave are fairly goodengines for literate programming in R, I often feel my hands are tied.For example:

  • I stared at the source code of Sweave and wished for hundreds of times,if only I could easily insert[width=.8\textwidth]between\includegraphicsand{my-plot.pdf}. (The official way in Sweave is\setkeys{Gin} but it is setting a global width, which is unrealisticsince we often have to set widths individually; yes, you can use\setkeys{Gin} for many times, but why not just provide an option foreach chunk?)
  • I wished for many times,if only I could use graphics devices otherthan PDF and postscript; now the dream has come true in the official R,but what I was hoping for was an option as simple asdev = 'png' ordev = 'CairoJPEG'.
  • I wished multiple plots in a code chunk could be recorded instead of onlythe last one.
  • I wished there was a way to round the numbers in\Sexpr{} other thanwriting expressions like\Sexpr{round(x, 3)} foreach single\Sexpr{}
  • I wished I did not have toprint() plots from.ggplot2 and a simpleqplot(x, y) would just give me a plot in Sweave.
  • I wished users would never need instructions onSweave.sty or run intotroubles due to the fact that LaTeX cannot findSweave.sty.
  • I wishedcacheSweave could print the results of a code chunk even ifit was cached.
  • I wishedbrew could supportgraphics.
  • I wishedR2HTML couldsupport R code syntax highlighting.
  • ...

The book Dynamic Documents with R and knitr

The packageknitr was designed to give the user access to every part ofthe process of dealing with a literate programming document, so there is noneed to hack at any core components if you want more freedom. I have gonethrough the source code ofpgfSweave andcacheSweave for a couple oftimes and I often feel uncomfortable with the large amount of code copiedfrom official R, especially when R has a new version released (I will beginto worry if the add-on packages are still up-to-date with the officialSweave).

Usage

library(knitr)?knitknit(input)

If options are not explicitly specified,knitr will try to guessreasonable default settings. A few manuals are available such as themainmanual, and thegraphicsmanual. For amore organized reference, see theknitr book.

License

This package is free and open source software, licensed under GPL.


[8]ページ先頭

©2009-2025 Movatter.jp