78 lines
94 KiB
HTML
78 lines
94 KiB
HTML
|
<!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>R Markdown (v1) Vignettes with 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>R Markdown (v1) Vignettes with knitr</h1></div>
|
||
|
<div class="author"><h2>Yihui Xie</h2></div>
|
||
|
<div class="date"><h3>2024-11-06</h3></div>
|
||
|
</div>
|
||
|
<div class="body">
|
||
|
<!--
|
||
|
%\VignetteEngine{litedown::vignette}
|
||
|
%\VignetteIndexEntry{An R Markdown Vignette with knitr}
|
||
|
-->
|
||
|
<p>Before R 3.0.0, only Sweave/PDF vignettes were supported in R. Markdown is gaining popularity over the years due to its simplicity, and R 3.0.0 starts to support package vignettes written in R Markdown.</p>
|
||
|
<blockquote>
|
||
|
<p>Please note this example is for <a href="https://cran.r-project.org/package=markdown">R Markdown v1</a> only. If you use <a href="https://rmarkdown.rstudio.com">R Markdown v2</a>, you should use the vignette engine <code>knitr::rmarkdown</code> instead of <code>knitr::knitr</code>.</p>
|
||
|
</blockquote>
|
||
|
<h2 id="sec:package-vignettes">Package vignettes</h2>
|
||
|
<p>To enable Markdown vignettes in an R package, you need to</p>
|
||
|
<ul>
|
||
|
<li>add <code>*.Rmd</code> files under the <code>vignettes</code> directory</li>
|
||
|
<li>add <code>VignetteBuilder: knitr</code> to the <code>DESCRIPTION</code> file</li>
|
||
|
<li>specify the vignette engine <code>\VignetteEngine{knitr::knitr}</code> in the <code>Rmd</code> files (inside HTML comments)</li>
|
||
|
</ul>
|
||
|
<h2 id="sec:view-vignettes">View vignettes</h2>
|
||
|
<p>And R will load the <strong>knitr</strong> package to build these vignettes to HTML files, and you can see them when you open the HTML help:</p>
|
||
|
<pre><code class="language-r">help(package = 'YourPackage', help_type = 'html')
|
||
|
# or see a standalone list of vignettes
|
||
|
browseVignettes('YourPackage')
|
||
|
</code></pre>
|
||
|
<h2 id="sec:examples">Examples</h2>
|
||
|
<p>Below are some code chunks as examples.</p>
|
||
|
<pre><code class="language-r">if (TRUE) cat('_hello_ **markdown**!', '\n')
|
||
|
</code></pre>
|
||
|
<p><em>hello</em> <strong>markdown</strong>!</p>
|
||
|
<p>Normally you do not need any chunk options.</p>
|
||
|
<pre><code class="language-r">1+1
|
||
|
</code></pre>
|
||
|
<pre><code>#> [1] 2
|
||
|
</code></pre>
|
||
|
<pre><code class="language-r">10:1
|
||
|
</code></pre>
|
||
|
<pre><code>#> [1] 10 9 8 7 6 5 4 3 2 1
|
||
|
</code></pre>
|
||
|
<pre><code class="language-r">rnorm(5)^2
|
||
|
</code></pre>
|
||
|
<pre><code>#> [1] 3.98959 0.01359 0.84722 6.17346 0.04204
|
||
|
</code></pre>
|
||
|
<pre><code class="language-r">strsplit('hello, markdown vignettes', '')
|
||
|
</code></pre>
|
||
|
<pre><code>#> [[1]]
|
||
|
#> [1] "h" "e" "l" "l" "o" "," " " "m" "a" "r" "k" "d" "o" "w" "n" " " "v" "i" "g"
|
||
|
#> [20] "n" "e" "t" "t" "e" "s"
|
||
|
#>
|
||
|
</code></pre>
|
||
|
<p>Feel free to draw beautiful plots and write math \(P(X>x)=\alpha/2\).</p>
|
||
|
<pre><code class="language-r">n=300; set.seed(123)
|
||
|
par(mar=c(4,4,.1,.1))
|
||
|
plot(rnorm(n), rnorm(n), pch=21, cex=5*runif(n), col='white', bg='gray')
|
||
|
</code></pre>
|
||
|
<p><img src="data:image/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RSyuDwQmIoAs3XXXXb1kKWXjBbTXXnttaWlicdpWQZoEcJ922mkFTJAju3j7iPtCoODjGudDAoFAIBCYE4EgTHOiGWkFAhkI/OQnPyluv/32jCt/cQly4J6TTz65SNaWX5zdrl/3uc99invvvbd8KW9TcPy+fftK993pp59eujojhmm7+kfUNhBYFALbG0m6KEQj3UCgBwEvkxXcPVSQBMRpm0WQ/Je+9KXihhtu6FxJyOok3mkMztuMb9Q9EAgE2hEIwtSOTZwJBBaCwNe//vVR6bJM+WyzIJvXXXddFgQ/+MEPSldmkKYsuOKiQCAQ6EEgCFMPQHE6EJgTAfFLU14ou83Kn/vt5ptvHtQcVhvec889EdM0CLW4OBAIBJoQCMLUhEocCwQWhIB4minvR7MabFsFYfrWt741uPpf/OIXO913gxOMGwKBQGArEQjCtJXNHpXeSQQe/ehHj8pesLeVYG3CerXJq8O448YIK1NIIBAIBAJTEQjCNBXBuD8QGIjA4Ycf3kl82pKzcWPXii/nrCDbVLF1wBjhxtxkXMZgEvcEAoHAcASCMA3HLO4IBCYhwFLkHWdDBBk64YQTRhGtIfms8rVjXZleM7PJlrdVbrMoWyCwSQgEYdqk1oy6rAUCduv2qo9jjjkmq7ysIxdeeGH5frmsGzb0Ipa5MeK+sDCNQS7uCQQCgSoCQZiqaMTvQGBJCDzwgQ8sN6E86aSTOpU564gNGO0/tK2vRUlNwjI3Jv7riU98YgHvkEAgEAgEpiAQO31PQS/uDQQmIvDkJz+53JX6zjvvLF/xId4G
|
||
|
</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>
|