Skip to content

Instantly share code, notes, and snippets.

@eugeneteo
Last active August 29, 2015 14:07
Show Gist options
  • Save eugeneteo/b65b3f6648959fce964f to your computer and use it in GitHub Desktop.
Save eugeneteo/b65b3f6648959fce964f to your computer and use it in GitHub Desktop.
pipeR-tutorial gitbook to PDF
$ gitbook --version
1.1.0
$ ebook-convert --version
ebook-convert (calibre 2.5.0)
Created by: Kovid Goyal <kovid@kovidgoyal.net>
sudo npm install gitbook -g
sudo npm install gitbook-plugin-ga
sudo npm install gitbook-plugin-katex
# Install calibre at http://calibre-ebook.com/
export PATH=$PATH:/Applications/calibre.app/Contents/MacOS
git clone https://github.com/renkun-ken/pipeR-tutorial; cd pipeR-tutorial
# Download and unarchive pipeR-tutorial.diff
patch -p1 < ../gistb65b3f6648959fce964f-b8cd689d1f9c6cf41806d143ecd012fcf2c89d55/pipeR-tutorial.diff
gitbook build .
gitbook pdf ./ -o ./pipeR-tutorial.pdf --config=book.json
gitbook epub ./ -o ./pipeR-tutorial.epub --config=book.json
Ref:
https://twitter.com/renkun_ken/status/519758514571329536
https://github.com/renkun-ken/pipeR-tutorial/issues/4
diff --git a/Examples/dplyr.md b/Examples/dplyr.md
index 9137dea..440d39a 100644
--- a/Examples/dplyr.md
+++ b/Examples/dplyr.md
@@ -73,7 +73,7 @@ hflights %>>%
main = "Average flight speed"))
```
-<img src="figure/barplot.png" title="plot of chunk barplot" alt="plot of chunk barplot" style="display: block; margin: auto;" />
+<img src="Examples/figure/barplot.png" title="plot of chunk barplot" alt="plot of chunk barplot" style="display: block; margin: auto;" />
The code is quite straightforward and almost close to plain English. In fact, one of the merits of dplyr is that it defines a domain specific language tailored for the needs in data manipulation. `filter()`, `mutate()`, `group_by()`, `summarize()`, and unused `select()` are all *verb* functions defined as chainable data commands.
@@ -98,7 +98,7 @@ hflights2 %>>%
boxplot(main = "Boxplot of flight speed sorted by median")
```
-<img src="figure/boxplot-speed.png" title="plot of chunk boxplot-speed" alt="plot of chunk boxplot-speed" style="display: block; margin: auto;" />
+<img src="Examples/figure/boxplot-speed.png" title="plot of chunk boxplot-speed" alt="plot of chunk boxplot-speed" style="display: block; margin: auto;" />
Note that some carriers have stable speeds and others don't. To see it more clearly, we rearrange the columns by the standard deviation of each group.
@@ -109,7 +109,7 @@ hflights3 %>>%
boxplot(main = "Boxplot of flight speed sorted by sd")
```
-<img src="figure/boxplot-speed-sd.png" title="plot of chunk boxplot-speed-sd" alt="plot of chunk boxplot-speed-sd" style="display: block; margin: auto;" />
+<img src="Examples/figure/boxplot-speed-sd.png" title="plot of chunk boxplot-speed-sd" alt="plot of chunk boxplot-speed-sd" style="display: block; margin: auto;" />
To build a better qualification standard, we can divide the mean by the standard deviation of the speed figures in each group.
@@ -120,7 +120,7 @@ hflights3 %>>%
boxplot(main = "Boxplot of flight speed sorted by mean/sd")
```
-<img src="figure/boxplot-speed-msd.png" title="plot of chunk boxplot-speed-msd" alt="plot of chunk boxplot-speed-msd" style="display: block; margin: auto;" />
+<img src="Examples/figure/boxplot-speed-msd.png" title="plot of chunk boxplot-speed-msd" alt="plot of chunk boxplot-speed-msd" style="display: block; margin: auto;" />
Note that for particular destination and origin, we can see which route is faster.
diff --git a/Examples/rlist.md b/Examples/rlist.md
index ac32ce5..81b48a5 100644
--- a/Examples/rlist.md
+++ b/Examples/rlist.md
@@ -58,7 +58,7 @@ repos %>>%
)
```
-<img src="figure/most-watched-repos.png" title="plot of chunk most-watched-repos" alt="plot of chunk most-watched-repos" style="display: block; margin: auto;" />
+<img src="Examples/figure/most-watched-repos.png" title="plot of chunk most-watched-repos" alt="plot of chunk most-watched-repos" style="display: block; margin: auto;" />
Then we can use similar way to see repos mainly written in R with most forks. Note that in the previous code, we save the filtered results to `active_repos` for further use so that we don't have to transform the data every time.
@@ -77,7 +77,7 @@ active_repos %>>%
)
```
-<img src="figure/most-fork-repos.png" title="plot of chunk most-fork-repos" alt="plot of chunk most-fork-repos" style="display: block; margin: auto;" />
+<img src="Examples/figure/most-fork-repos.png" title="plot of chunk most-fork-repos" alt="plot of chunk most-fork-repos" style="display: block; margin: auto;" />
We are also interested in the repos whose name contains *plot* or *vis*. Let's see what they are arranged by popularity measured in count of stargazers.
diff --git a/Getting-started/First-example.md b/Getting-started/First-example.md
index 8c1f3c0..7aea3aa 100644
--- a/Getting-started/First-example.md
+++ b/Getting-started/First-example.md
@@ -13,7 +13,7 @@ density_mtcars <- density(sample_mtcars, kernel = "gaussian")
plot(density_mtcars, col = "red", main="density of mpg (bootstrap)")
```
-<img src="figure/bootstrap.png" title="plot of chunk bootstrap" alt="plot of chunk bootstrap" style="display: block; margin: auto;" />
+<img src="Getting-started/figure/bootstrap.png" title="plot of chunk bootstrap" alt="plot of chunk bootstrap" style="display: block; margin: auto;" />
The traditional approach introduces some intermediate variables which may be used only once. If one wants to avoid these variables and combine the lines together, the code will become
diff --git a/Pipe-function/Pipe-to-first-argument.md b/Pipe-function/Pipe-to-first-argument.md
index 6de28d5..ff5dc6d 100644
--- a/Pipe-function/Pipe-to-first-argument.md
+++ b/Pipe-function/Pipe-to-first-argument.md
@@ -113,7 +113,7 @@ Pipe(mtcars$mpg)$
plot(col = "red", main = sprintf("mpg (%d obs.)", length(.)))
```
-<img src="figure/pipe-dot.png" title="plot of chunk pipe-dot" alt="plot of chunk pipe-dot" style="display: block; margin: auto;" />
+<img src="Pipe-function/figure/pipe-dot.png" title="plot of chunk pipe-dot" alt="plot of chunk pipe-dot" style="display: block; margin: auto;" />
You may notice that the previous `plot()` only produces graphics but the `NULL` value it returns are not explicitly printed. `Pipe` by design mutes `NULL` value as being printed. However, not all graphics functions return `NULL`. `hist()` is one example.
@@ -123,7 +123,7 @@ Pipe(mtcars$mpg)$
hist(main = "distribution of mpg")
```
-<img src="figure/pipe-hist.png" title="plot of chunk pipe-hist" alt="plot of chunk pipe-hist" style="display: block; margin: auto;" />
+<img src="Pipe-function/figure/pipe-hist.png" title="plot of chunk pipe-hist" alt="plot of chunk pipe-hist" style="display: block; margin: auto;" />
The output is no longer `NULL` but a new `Pipe` object consisting of a `histogram` object with a few elements indicating its properties.
@@ -196,7 +196,7 @@ density_plot(col = "blue", main = "blue points")
density_plot(col = "gray", type = "o", main = "gray circles")
```
-<img src="figure/partial-function.png" title="plot of chunk partial-function" alt="plot of chunk partial-function" style="display: block; margin: auto;" />
+<img src="Pipe-function/figure/partial-function.png" title="plot of chunk partial-function" alt="plot of chunk partial-function" style="display: block; margin: auto;" />
Note that when the partial function is determined, all the steps before the function are already evaluated, which means that the random numbers will not change each time we call the partial function `density_plot()`.
diff --git a/Pipe-operator/Extract-element.md b/Pipe-operator/Extract-element.md
index a70f11b..66d2cae 100644
--- a/Pipe-operator/Extract-element.md
+++ b/Pipe-operator/Extract-element.md
@@ -66,7 +66,7 @@ y <- 2*x + rnorm(150)*0.5
matplot(cbind(x,y),type = "l")
```
-<img src="figure/extract-s4.png" title="plot of chunk extract-s4" alt="plot of chunk extract-s4" style="display: block; margin: auto;" />
+<img src="Pipe-operator/figure/extract-s4.png" title="plot of chunk extract-s4" alt="plot of chunk extract-s4" style="display: block; margin: auto;" />
Now given the data, we can perform an ADF test on the residues of linear model `lm(y ~ x + 0)`.
diff --git a/Pipe-operator/Pipe-for-side-effect.md b/Pipe-operator/Pipe-for-side-effect.md
index b638632..9ed41a9 100644
--- a/Pipe-operator/Pipe-for-side-effect.md
+++ b/Pipe-operator/Pipe-for-side-effect.md
@@ -13,7 +13,7 @@ For example, we draw a scatter plot and saves its returned value to `z`.
z <- plot(mtcars$mpg)
```
-<img src="figure/simple-plot.png" title="plot of chunk simple-plot" alt="plot of chunk simple-plot" style="display: block; margin: auto;" />
+<img src="Pipe-operator/figure/simple-plot.png" title="plot of chunk simple-plot" alt="plot of chunk simple-plot" style="display: block; margin: auto;" />
```r
z
@@ -91,7 +91,7 @@ mtcars %>>%
summary()
```
-<img src="figure/side-effect-graphics.png" title="plot of chunk side-effect-graphics" alt="plot of chunk side-effect-graphics" style="display: block; margin: auto;" />
+<img src="Pipe-operator/figure/side-effect-graphics.png" title="plot of chunk side-effect-graphics" alt="plot of chunk side-effect-graphics" style="display: block; margin: auto;" />
```
#
diff --git a/Pipe-operator/Pipe-to-dot.md b/Pipe-operator/Pipe-to-dot.md
index 7b89a37..1bcc656 100644
--- a/Pipe-operator/Pipe-to-dot.md
+++ b/Pipe-operator/Pipe-to-dot.md
@@ -94,7 +94,7 @@ mtcars %>>% {
}
```
-<img src="figure/multiline.png" title="plot of chunk multiline" alt="plot of chunk multiline" style="display: block; margin: auto;" />
+<img src="Pipe-operator/figure/multiline.png" title="plot of chunk multiline" alt="plot of chunk multiline" style="display: block; margin: auto;" />
Another thing is that the meaning of nested dots are always determined by the working operator for that dot symbol. For example, the above code can be refined to
@@ -107,7 +107,7 @@ mtcars %>>% {
}
```
-<img src="figure/nested_dots.png" title="plot of chunk nested_dots" alt="plot of chunk nested_dots" style="display: block; margin: auto;" />
+<img src="Pipe-operator/figure/nested_dots.png" title="plot of chunk nested_dots" alt="plot of chunk nested_dots" style="display: block; margin: auto;" />
It should be obvious that `.` below `par()` belong to the first `%>>%` that works with `mtcars` while `.` in `length()` belong to the operator that works with `.$mpg` so that it can correctly show the length of `mpg` (32) rather than that of `mtcars` (11).
@@ -138,7 +138,7 @@ density_plot("rectangular")
density_plot("triangular")
```
-<img src="figure/create-closure.png" title="plot of chunk create-closure" alt="plot of chunk create-closure" style="display: block; margin: auto;" />
+<img src="Pipe-operator/figure/create-closure.png" title="plot of chunk create-closure" alt="plot of chunk create-closure" style="display: block; margin: auto;" />
However, if the enclosed function is called directly in the pipeline, `%>>%` will pipe the left value to its first argument because here the only difference between first-argument piping examples and this example is the function no longer has a name but created inline.
diff --git a/Pipe-operator/Pipe-to-first-argument.md b/Pipe-operator/Pipe-to-first-argument.md
index 5162001..8c8f9e0 100644
--- a/Pipe-operator/Pipe-to-first-argument.md
+++ b/Pipe-operator/Pipe-to-first-argument.md
@@ -70,7 +70,7 @@ mtcars$mpg %>>%
plot(col="red", main=sprintf("number of points: %d",length(.)))
```
-<img src="figure/mtcars-with-title.png" title="plot of chunk mtcars-with-title" alt="plot of chunk mtcars-with-title" style="display: block; margin: auto;" />
+<img src="Pipe-operator/figure/mtcars-with-title.png" title="plot of chunk mtcars-with-title" alt="plot of chunk mtcars-with-title" style="display: block; margin: auto;" />
Take a sample from the lower letters of half the population.
diff --git a/book.json b/book.json
index 3234014..137d345 100644
--- a/book.json
+++ b/book.json
@@ -2,7 +2,7 @@
"github": "https://github.com/renkun-ken/pipeR-tutorial",
"githubHost": "https://github.com/",
- "plugins": ["ga","katex","-mathjax"],
+ "plugins": ["-ga","-katex","-mathjax"],
"pluginsConfig": {
"ga": {
"token": "UA-47159422-1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment