101 lines
44 KiB
HTML
Raw Permalink Normal View History

2025-01-12 00:52:51 +08:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="generator" content="litedown 0.4">
<title>Not An Introduction to knitr</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@xiee/utils@1.13.44/css/prism-xcode.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@xiee/utils@1.13.44/css/default.min.css">
</head>
<body>
<div class="frontmatter">
<div class="title"><h1>Not An Introduction to knitr</h1></div>
<div class="author"><h2>Yihui Xie</h2></div>
<div class="date"><h3>2024-11-06</h3></div>
</div>
<div class="body">
<p>The <strong>knitr</strong> package is an alternative tool to Sweave based on a different
design with more features. This document is not an introduction, but only serves
as a placeholder to guide you to the real manuals, which are available on the
package website <a href="https://yihui.org/knitr/">https://yihui.org/knitr/</a> (e.g. the <a href="https://yihui.org/knitr/demo/manual/">main
manual</a> and the <a href="https://yihui.org/knitr/demo/graphics/">graphics
manual</a> ), and remember to read the help
pages of functions in this package. There is a book “Dynamic Docuemnts with R
and knitr” for this package, too.</p>
<p>Anyway, here is a code chunk that shows you can compile vignettes with <strong>knitr</strong>
as well using R 3.0.x, which supports non-Sweave vignettes:</p>
<pre><code class="language-r">options(digits = 4)
rnorm(20)
</code></pre>
<pre><code>#&gt; [1] -0.53125 -1.10327 0.77924 -1.64279 2.12976 0.14292 -0.61442 -0.83602
#&gt; [9] 0.55669 -3.08241 -1.60739 -0.51008 1.40616 0.10845 2.56358 -0.66988
#&gt; [17] -1.49418 -0.19985 -0.07476 -0.43768
</code></pre>
<pre><code class="language-r">fit = lm(dist ~ speed, data = cars)
b = coef(fit)
</code></pre>
<table>
<thead>
<tr>
<th></th>
<th align="right">Estimate</th>
<th align="right">Std. Error</th>
<th align="right">t value</th>
<th align="right">Pr(&gt;|t|)</th>
</tr>
</thead>
<tbody>
<tr>
<td>(Intercept)</td>
<td align="right">-17.579</td>
<td align="right">6.758</td>
<td align="right">-2.601</td>
<td align="right">0.012</td>
</tr>
<tr>
<td>speed</td>
<td align="right">3.932</td>
<td align="right">0.416</td>
<td align="right">9.464</td>
<td align="right">0.000</td>
</tr>
</tbody>
</table>
<p>The fitted regression equation is \(Y=-17.6+3.93x\).</p>
<pre><code class="language-r">par(mar=c(4, 4, 1, .1))
plot(cars, pch = 20)
abline(fit, col = 'red')
</code></pre>
<div id="fig:graphics" class="figure">
<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkwAAAJMCAYAAAAIZPnDAAAEDmlDQ1BrQ0dDb2xvclNwYWNlR2VuZXJpY1JHQgAAOI2NVV1oHFUUPpu5syskzoPUpqaSDv41lLRsUtGE2uj+ZbNt3CyTbLRBkMns3Z1pJjPj/KRpKT4UQRDBqOCT4P9bwSchaqvtiy2itFCiBIMo+ND6R6HSFwnruTOzu5O4a73L3PnmnO9+595z7t4LkLgsW5beJQIsGq4t5dPis8fmxMQ6dMF90A190C0rjpUqlSYBG+PCv9rt7yDG3tf2t/f/Z+uuUEcBiN2F2Kw4yiLiZQD+FcWyXYAEQfvICddi+AnEO2ycIOISw7UAVxieD/Cyz5mRMohfRSwoqoz+xNuIB+cj9loEB3Pw2448NaitKSLLRck2q5pOI9O9g/t/tkXda8Tbg0+PszB9FN8DuPaXKnKW4YcQn1Xk3HSIry5ps8UQ/2W5aQnxIwBdu7yFcgrxPsRjVXu8HOh0qao30cArp9SZZxDfg3h1wTzKxu5E/LUxX5wKdX5SnAzmDx4A4OIqLbB69yMesE1pKojLjVdoNsfyiPi45hZmAn3uLWdpOtfQOaVmikEs7ovj8hFWpz7EV6mel0L9Xy23FMYlPYZenAx0yDB1/PX6dledmQjikjkXCxqMJS9WtfFCyH9XtSekEF+2dH+P4tzITduTygGfv58a5VCTH5PtXD7EFZiNyUDBhHnsFTBgE0SQIA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AABBGIIEDDFQGEXAggg
<div class="fig-caption">
<p><span class="ref-number-fig">1</span>
A scatterplot with a regression line.</p>
</div>
</div>
<h2 id="sec:references">References</h2>
<p>Xie Y (2024).
<em>knitr: A General-Purpose Package for Dynamic Report Generation in R</em>.
R package version 1.49, <a href="https://yihui.org/knitr/">https://yihui.org/knitr/</a>.
</p>
<p>Xie Y (2015).
<em>Dynamic Documents with R and knitr</em>, 2nd edition.
Chapman and Hall/CRC, Boca Raton, Florida.
ISBN 978-1498716963, <a href="https://yihui.org/knitr/">https://yihui.org/knitr/</a>.
</p>
<p>Xie Y (2014).
&ldquo;knitr: A Comprehensive Tool for Reproducible Research in R.&rdquo;
In Stodden V, Leisch F, Peng RD (eds.), <em>Implementing Reproducible Computational Research</em>.
Chapman and Hall/CRC.
ISBN 978-1466561595.
</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-core.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/combine/npm/katex@0.16.11/dist/katex.min.js,npm/katex@0.16.11/dist/contrib/auto-render.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/@xiee/utils@1.13.44/js/render-katex.min.js" defer></script>
</body>
</html>