Permalink
Browse files

simplify words in knitr-minimal.Rmd but cover more features

  • Loading branch information...
1 parent ebd8176 commit f5a63473574431dc70b327260afeb99c53fa5cce @yihui committed Nov 23, 2012
Showing with 42 additions and 19 deletions.
  1. +42 −19 inst/examples/knitr-minimal.Rmd
@@ -1,35 +1,58 @@
-This is a minimal example of using **knitr** with in HTML pages. I am actually
-using markdown here since it is more convenient in GitHub.
+# A Minimal Example for Markdown
-First, the input file was named as `knitr-minimal.Rmd`
-([source](https://github.com/yihui/knitr/blob/master/inst/examples/knitr-minimal.Rmd)),
-and **knitr** will automatically determine the output filename to be
-`knitr-minimal.md` (`*.Rmd --> *.md`).
+This is a minimal example of using **knitr** to produce an _HTML_ page from _Markdown_.
+
+## R code chunks
```{r setup}
-# set global chunk options: images will be 5x5 inches
-opts_chunk$set(fig.width=5, fig.height=5)
+# set global chunk options: images will be 7x5 inches
+opts_chunk$set(fig.width=7, fig.height=5)
```
Now we write some code chunks in this markdown file:
-``` {r}
-## a simple calculator
-(x <- 1+1)
-## boring random numbers
+```{r computing}
+x <- 1+1 # a simple calculator
set.seed(123)
-rnorm(5)
+rnorm(5) # boring random numbers
```
We can also produce plots:
-``` {r md-cars-scatter, message=FALSE}
-library(ggplot2)
-qplot(hp, mpg, data=mtcars)+geom_smooth()
+```{r graphics}
+par(mar = c(4, 4, .1, .1))
+with(mtcars, {
+ plot(mpg~hp, pch=20, col='darkgray')
+ lines(lowess(hp, mpg))
+})
```
-Inline R code is also supported, e.g. the value of `x` is `r x`, and 2 times pi
+## Inline code
+
+Inline R code is also supported, e.g. the value of `x` is `r x`, and 2 &times; &pi;
= `r 2*pi`.
-So no more hesitation on using GitHub and **knitr**! You just write a minimal
-amount of code to get beautiful output on the web.
+## Math
+
+LaTeX math as usual: $f(\alpha, \beta) \propto x^{\alpha-1}(1-x)^{\beta-1}$.
+
+## Misc
+
+You can indent code chunks so they can nest within other environments such as lists.
+
+1. the area of a circle with radius x
+ ```{r foo}
+ pi * x^2
+ ```
+2. OK, that is great
+
+To compile me, use
+
+```{r compile, eval=FALSE}
+library(knitr)
+knit('knitr-minimal.Rmd')
+```
+
+## Conclusion
+
+Markdown is super easy to write. Go to **knitr** [homepage](http://yihui.name/knitr) for details.

0 comments on commit f5a6347

Please sign in to comment.