Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Introduction {#intro} | ||
|
||
You can label chapter and section titles using `{#label}` after them, e.g., we can reference Chapter \@ref(intro). If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \@ref(methods). | ||
|
||
Figures and tables with captions will be placed in `figure` and `table` environments, respectively. | ||
|
||
```{r nice-fig, fig.cap='Here is a nice figure!', out.width='80%', fig.asp=.75, fig.align='center'} | ||
par(mar = c(4, 4, .1, .1)) | ||
plot(pressure, type = 'b', pch = 19) | ||
``` | ||
|
||
Reference a figure by its code chunk label with the `fig:` prefix, e.g., see Figure \@ref(fig:nice-fig). Similarly, you can reference tables generated from `knitr::kable()`, e.g., see Table \@ref(tab:nice-tab). | ||
|
||
```{r nice-tab} | ||
knitr::kable(head(iris, 20), caption = 'Here is a nice table!', booktabs = TRUE) | ||
``` | ||
|
||
You can write citations, too. For example, we are using the **bookdown** package [@R-bookdown] in this sample book, which was built on top of R Markdown and **knitr** [@xie2015]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Literature | ||
|
||
Here is a review of existing methods. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Methods | ||
|
||
We describe our methods in this chapter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Applications | ||
|
||
Some _significant_ applications are demonstrated in this chapter. | ||
|
||
## Example one | ||
|
||
## Example two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Final Words | ||
|
||
We have finished a nice book. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
`r if (knitr:::is_html_output()) '# References'` | ||
|
||
```{r include=FALSE} | ||
# automatically create a bib database for R packages | ||
knitr::write_bib(c( | ||
.packages(), 'bookdown', 'knitr', 'rmarkdown' | ||
), 'packages.bib') | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
RMD_FILES := $(filter-out _%, $(wildcard *.Rmd)) | ||
HTML_FILES := $(patsubst %.Rmd, %.html, $(RMD_FILES)) | ||
|
||
all: $(HTML_FILES) | ||
|
||
%.html: %.Rmd | ||
Rscript -e "bookdown::render_book('$<', 'bookdown::html_chapters')" | ||
|
||
pdf: book.pdf | ||
|
||
%.pdf: %.Rmd $(RMD_FILES) | ||
Rscript -e "bookdown::render_book('$<', 'bookdown::pdf_book')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
main_rmd: "book.Rmd" | ||
chapter_name: "CHAPTER " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@Book{xie2015, | ||
title = {Dynamic Documents with {R} and knitr}, | ||
author = {Yihui Xie}, | ||
publisher = {Chapman and Hall/CRC}, | ||
address = {Boca Raton, Florida}, | ||
year = {2015}, | ||
edition = {2nd}, | ||
note = {ISBN 978-1498716963}, | ||
url = {http://yihui.name/knitr/}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: knitr | ||
LaTeX: pdfLaTeX | ||
|
||
AutoAppendNewline: Yes | ||
StripTrailingWhitespace: Yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: "A Minimal Book Example" | ||
author: "Yihui Xie" | ||
date: "`r Sys.Date()`" | ||
knit: "bookdown::render_book" | ||
output: | ||
bookdown::html_chapters: | ||
css: style.css | ||
md_extensions: +markdown_in_html_blocks | ||
bookdown::pdf_book: | ||
includes: | ||
in_header: preamble.tex | ||
keep_tex: yes | ||
latex_engine: xelatex | ||
documentclass: book | ||
bibliography: [book.bib, packages.bib] | ||
biblio-style: apalike | ||
link-citations: yes | ||
--- | ||
|
||
# Prerequisites | ||
|
||
This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$. | ||
|
||
For now, you have to install the development versions of **bookdown**, **rmarkdown**, and **knitr**: | ||
|
||
```{r eval=FALSE} | ||
install.packages( | ||
c("bookdown", "knitr"), | ||
repos = c("http://yihui.name/xran", "http://cran.rstudio.com") | ||
) | ||
``` | ||
|
||
Remember each Rmd file contains one and only one chapter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\usepackage{booktabs} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.kable_wrapper { | ||
border-spacing: 20px 0; | ||
border-collapse: separate; | ||
border: none; | ||
margin: auto; | ||
} | ||
.kable_wrapper > tbody > tr > td { | ||
vertical-align: top; | ||
} | ||
p.caption { | ||
color: #777; | ||
margin-top: 10px; | ||
} | ||
p code { | ||
white-space: inherit; | ||
} | ||
pre { | ||
word-break: normal; | ||
word-wrap: normal; | ||
} | ||
pre code { | ||
white-space: inherit; | ||
} |