` not
50 | `
`
51 |
52 | ```
53 | .sourceCode {
54 | background-color: green;
55 | }
56 | ```
57 |
58 | ## Font awesome
59 |
60 | ````
61 | `r ''````{r setup, include=FALSE}
62 | htmltools::tagList(rmarkdown::html_dependency_font_awesome())
63 | ```
64 | ````
65 |
66 | ```{r setup, include=FALSE}
67 | htmltools::tagList(rmarkdown::html_dependency_font_awesome())
68 | ```
69 |
70 |
71 | [https://github.com/rstudio/rmarkdown/issues/813](https://github.com/rstudio/rmarkdown/issues/813){target="blank"}
72 |
73 |
74 | Use only 5.1.0 or earlier
75 |
76 | Can't find a cheatsheet for 5.1.0; here's the official 4.7.0 list:
77 |
78 | [https://fontawesome.com/v4.7.0/icons/](https://fontawesome.com/v4.7.0/icons/){target="blank"}
79 |
80 | ``
81 |
82 |
83 | ## CORS error in Chrome Console
84 |
85 | (Applies only to viewing Console locally, caused by `search_index.json`)
86 |
87 | Best solution: run a local server from rendered book folder
88 |
89 | Or, open Chrome from Terminal with:
90 |
91 | `/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files`
92 |
93 | ## Copy and paste JavaScript code
94 |
95 | Include: `klippy::klippy("js")` somewhere
96 |
97 | Not clear how **rmarkdown** use of `clipboard.js` interacts with **klippy** version but this appears to work.
98 |
99 | **rmarkdown** css for clipboard button however seems to take precedence over **klippy** so `klippy(position = ...)` doesn't work. If `class.source='klippy'` is added as a chunk option (see `?klippy`) no clipboard appears at all.
100 |
101 | ## `knitr::write_bib()`
102 |
103 | Getting a lot of warnings from `knitr::write_bib()`. `write_bib()` calls `citation()` with `auto=TRUE`. This creates a problem for the dev versions since they don't have a `Date/Publication` field, apparently it is added by CRAN.
104 |
105 | ```{r}
106 | library(ggplot2)
107 | packageVersion("ggplot2")
108 | citation("ggplot2", auto=TRUE)
109 | ```
110 |
111 | ## Github Actions
112 |
113 | Uses GitHub Pages: https://medium.com/@delucmat/how-to-publish-bookdown-projects-with-github-actions-on-github-pages-6e6aecc7331e
114 |
115 | Uses Netlify: https://www.hvitfeldt.me/blog/bookdown-netlify-github-actions/
116 |
117 | ### Tokens
118 |
119 | **GitHub Pages**: Create GitHub secrets GH_PAT and EMAIL. GH_PAT is a personal access token with repository access. EMAIL is the mail address you use to login to GitHub.
120 |
121 | GH_PAT: Go to the developer settings of your GitHub account and create a new token. Copy the code you’ll receive and go to your repository’s secrets in the tab “settings” (https://github.com///settings/secrets) and create a new secret named GH_PAT and paste the code of the token.
122 |
123 | EMAIL: Go to your repository’s secrets in the tab “settings” (https://github.com///settings/secrets) and create a new secret named EMAIL and enter your mail address that you use to login to GitHub.
124 |
125 | **Netlify**: create token in Netlify, add to GitHub Secrets as NETLIFY_AUTH_TOKEN
126 |
127 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/docs/search_index.json:
--------------------------------------------------------------------------------
1 | [
2 | ["index.html", "Notes Chapter 1 rmarkdown 1.1 Tables 1.2 Verbatim code chunks", " Notes Joyce Robbins 2019-12-06 Chapter 1 rmarkdown 1.1 Tables 1.1.1 Adjust column width with knitr::kable() html_table_width() function: html_table_width <- function(kable_output, width){ width_html <- paste0(paste0('<col width="', width, '">'), collapse = "\\n") sub("<table>", paste0("<table>\\n", width_html), kable_output) } https://github.com/rstudio/bookdown/issues/122 1.1.2 Line breaks in table cells with knitr::kable() best option add <br> x <- data.frame(a = "asdf asdf", b = "asdf<br>asdf") knitr::kable(x) a b asdf asdf asdfasdf 1.1.3 Line breaks in table cells with knitr::kable(), using format="html" Add escape=FALSE x <- data.frame(a = "asdf asdf", b = "asdf<br>asdf") knitr::kable(x, format="html", escape=FALSE) a b asdf asdf asdfasdf 1.2 Verbatim code chunks https://rmarkdown.rstudio.com/articles_verbatim.html Why it works: https://yihui.name/en/2017/11/knitr-verbatim-code-chunk/ "],
3 | ["bookdown.html", "Chapter 2 bookdown 2.1 Figures 2.2 Code styling 2.3 Font awesome 2.4 CORS error in Chrome Console 2.5 Copy and paste JavaScript code 2.6 knitr::write_bib()", " Chapter 2 bookdown 2.1 Figures out.width seems to be the secret to controlling figure sizes simultaneously in gitbook and pdf_book formats: ```{r, out.width='25%', fig.align='center', echo=FALSE} webshot::webshot(\"http://www.clocktab.com\", selector=\"#timeTable\") ``` 2.2 Code styling Have tried everything to control the background color of code chunks as in myslidy.css (see d3 lectures folder) to no avail. Gitbook appears to work differently. I can control some things but not all. Works: pre { font-size: 200%; font-weight: bold; width: 80%; } .sourceCode { font-size: 200%; width: 40%; } Doesn’t work: pre { font-family: "Times New Roman"; border-color: green; color: orange; background-color: green; } This works for <div class="sourceCode"> not <pre class="sourceCode"> .sourceCode { background-color: green; } 2.3 Font awesome ```{r setup, include=FALSE} htmltools::tagList(rmarkdown::html_dependency_font_awesome()) ``` https://github.com/rstudio/rmarkdown/issues/813 Use only 5.1.0 or earlier Can’t find a cheatsheet for 5.1.0; here’s the official 4.7.0 list: https://fontawesome.com/v4.7.0/icons/ <i class="fa fa-fort-awesome"></i> 2.4 CORS error in Chrome Console (Applies only to viewing Console locally, caused by search_index.json) Best solution: run a local server from rendered book folder Or, open Chrome from Terminal with: /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --allow-file-access-from-files 2.5 Copy and paste JavaScript code Include: klippy::klippy("js") somewhere Not clear how rmarkdown use of clipboard.js interacts with klippy version but this appears to work. rmarkdown css for clipboard button however seems to take precedence over klippy so klippy(position = ...) doesn’t work. If class.source='klippy' is added as a chunk option (see ?klippy) no clipboard appears at all. 2.6 knitr::write_bib() Getting a lot of warnings from knitr::write_bib(). write_bib() calls citation() with auto=TRUE. This creates a problem for the dev versions since they don’t have a Date/Publication field, apparently it is added by CRAN. library(ggplot2) packageVersion("ggplot2") ## [1] '3.2.1.9000' citation("ggplot2", auto=TRUE) ## Warning in citation("ggplot2", auto = TRUE): no date field in ## DESCRIPTION file of package 'ggplot2' ## ## To cite package 'ggplot2' in publications use: ## ## Hadley Wickham, Winston Chang, Lionel Henry, Thomas Lin ## Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki ## Yutani and Dewey Dunnington (2019). ggplot2: Create ## Elegant Data Visualisations Using the Grammar of Graphics. ## http://ggplot2.tidyverse.org, ## https://github.com/tidyverse/ggplot2. ## ## A BibTeX entry for LaTeX users is ## ## @Manual{, ## title = {ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics}, ## author = {Hadley Wickham and Winston Chang and Lionel Henry and Thomas Lin Pedersen and Kohske Takahashi and Claus Wilke and Kara Woo and Hiroaki Yutani and Dewey Dunnington}, ## year = {2019}, ## note = {http://ggplot2.tidyverse.org, https://github.com/tidyverse/ggplot2}, ## } "]
4 | ]
5 |
--------------------------------------------------------------------------------
/docs/libs/gitbook-2.6.7/js/plugin-fontsettings.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2 | var fontState;
3 |
4 | var THEMES = {
5 | "white": 0,
6 | "sepia": 1,
7 | "night": 2
8 | };
9 |
10 | var FAMILY = {
11 | "serif": 0,
12 | "sans": 1
13 | };
14 |
15 | // Save current font settings
16 | function saveFontSettings() {
17 | gitbook.storage.set("fontState", fontState);
18 | update();
19 | }
20 |
21 | // Increase font size
22 | function enlargeFontSize(e) {
23 | e.preventDefault();
24 | if (fontState.size >= 4) return;
25 |
26 | fontState.size++;
27 | saveFontSettings();
28 | };
29 |
30 | // Decrease font size
31 | function reduceFontSize(e) {
32 | e.preventDefault();
33 | if (fontState.size <= 0) return;
34 |
35 | fontState.size--;
36 | saveFontSettings();
37 | };
38 |
39 | // Change font family
40 | function changeFontFamily(index, e) {
41 | e.preventDefault();
42 |
43 | fontState.family = index;
44 | saveFontSettings();
45 | };
46 |
47 | // Change type of color
48 | function changeColorTheme(index, e) {
49 | e.preventDefault();
50 |
51 | var $book = $(".book");
52 |
53 | if (fontState.theme !== 0)
54 | $book.removeClass("color-theme-"+fontState.theme);
55 |
56 | fontState.theme = index;
57 | if (fontState.theme !== 0)
58 | $book.addClass("color-theme-"+fontState.theme);
59 |
60 | saveFontSettings();
61 | };
62 |
63 | function update() {
64 | var $book = gitbook.state.$book;
65 |
66 | $(".font-settings .font-family-list li").removeClass("active");
67 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active");
68 |
69 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
70 | $book.addClass("font-size-"+fontState.size);
71 | $book.addClass("font-family-"+fontState.family);
72 |
73 | if(fontState.theme !== 0) {
74 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
75 | $book.addClass("color-theme-"+fontState.theme);
76 | }
77 | };
78 |
79 | function init(config) {
80 | var $bookBody, $book;
81 |
82 | //Find DOM elements.
83 | $book = gitbook.state.$book;
84 | $bookBody = $book.find(".book-body");
85 |
86 | // Instantiate font state object
87 | fontState = gitbook.storage.get("fontState", {
88 | size: config.size || 2,
89 | family: FAMILY[config.family || "sans"],
90 | theme: THEMES[config.theme || "white"]
91 | });
92 |
93 | update();
94 | };
95 |
96 |
97 | gitbook.events.bind("start", function(e, config) {
98 | var opts = config.fontsettings;
99 | if (!opts) return;
100 |
101 | // Create buttons in toolbar
102 | gitbook.toolbar.createButton({
103 | icon: 'fa fa-font',
104 | label: 'Font Settings',
105 | className: 'font-settings',
106 | dropdown: [
107 | [
108 | {
109 | text: 'A',
110 | className: 'font-reduce',
111 | onClick: reduceFontSize
112 | },
113 | {
114 | text: 'A',
115 | className: 'font-enlarge',
116 | onClick: enlargeFontSize
117 | }
118 | ],
119 | [
120 | {
121 | text: 'Serif',
122 | onClick: _.partial(changeFontFamily, 0)
123 | },
124 | {
125 | text: 'Sans',
126 | onClick: _.partial(changeFontFamily, 1)
127 | }
128 | ],
129 | [
130 | {
131 | text: 'White',
132 | onClick: _.partial(changeColorTheme, 0)
133 | },
134 | {
135 | text: 'Sepia',
136 | onClick: _.partial(changeColorTheme, 1)
137 | },
138 | {
139 | text: 'Night',
140 | onClick: _.partial(changeColorTheme, 2)
141 | }
142 | ]
143 | ]
144 | });
145 |
146 |
147 | // Init current settings
148 | init(opts);
149 | });
150 | });
151 |
152 |
153 |
--------------------------------------------------------------------------------
/docs/libs/gitbook-2.6.7/js/plugin-search.js:
--------------------------------------------------------------------------------
1 | gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
2 | var index = null;
3 | var $searchInput, $searchLabel, $searchForm;
4 | var $highlighted = [], hi, hiOpts = { className: 'search-highlight' };
5 | var collapse = false, toc_visible = [];
6 |
7 | // Use a specific index
8 | function loadIndex(data) {
9 | // [Yihui] In bookdown, I use a character matrix to store the chapter
10 | // content, and the index is dynamically built on the client side.
11 | // Gitbook prebuilds the index data instead: https://github.com/GitbookIO/plugin-search
12 | // We can certainly do that via R packages V8 and jsonlite, but let's
13 | // see how slow it really is before improving it. On the other hand,
14 | // lunr cannot handle non-English text very well, e.g. the default
15 | // tokenizer cannot deal with Chinese text, so we may want to replace
16 | // lunr with a dumb simple text matching approach.
17 | index = lunr(function () {
18 | this.ref('url');
19 | this.field('title', { boost: 10 });
20 | this.field('body');
21 | });
22 | data.map(function(item) {
23 | index.add({
24 | url: item[0],
25 | title: item[1],
26 | body: item[2]
27 | });
28 | });
29 | }
30 |
31 | // Fetch the search index
32 | function fetchIndex() {
33 | return $.getJSON(gitbook.state.basePath+"/search_index.json")
34 | .then(loadIndex); // [Yihui] we need to use this object later
35 | }
36 |
37 | // Search for a term and return results
38 | function search(q) {
39 | if (!index) return;
40 |
41 | var results = _.chain(index.search(q))
42 | .map(function(result) {
43 | var parts = result.ref.split("#");
44 | return {
45 | path: parts[0],
46 | hash: parts[1]
47 | };
48 | })
49 | .value();
50 |
51 | // [Yihui] Highlight the search keyword on current page
52 | $highlighted = results.length === 0 ? [] : $('.page-inner')
53 | .unhighlight(hiOpts).highlight(q, hiOpts).find('span.search-highlight');
54 | scrollToHighlighted(0);
55 |
56 | return results;
57 | }
58 |
59 | // [Yihui] Scroll the chapter body to the i-th highlighted string
60 | function scrollToHighlighted(d) {
61 | var n = $highlighted.length;
62 | hi = hi === undefined ? 0 : hi + d;
63 | // navignate to the previous/next page in the search results if reached the top/bottom
64 | var b = hi < 0;
65 | if (d !== 0 && (b || hi >= n)) {
66 | var path = currentPath(), n2 = toc_visible.length;
67 | if (n2 === 0) return;
68 | for (var i = b ? 0 : n2; (b && i < n2) || (!b && i >= 0); i += b ? 1 : -1) {
69 | if (toc_visible.eq(i).data('path') === path) break;
70 | }
71 | i += b ? -1 : 1;
72 | if (i < 0) i = n2 - 1;
73 | if (i >= n2) i = 0;
74 | var lnk = toc_visible.eq(i).find('a[href$=".html"]');
75 | if (lnk.length) lnk[0].click();
76 | return;
77 | }
78 | if (n === 0) return;
79 | var $p = $highlighted.eq(hi);
80 | $p[0].scrollIntoView();
81 | $highlighted.css('background-color', '');
82 | // an orange background color on the current item and removed later
83 | $p.css('background-color', 'orange');
84 | setTimeout(function() {
85 | $p.css('background-color', '');
86 | }, 2000);
87 | }
88 |
89 | function currentPath() {
90 | var href = window.location.pathname;
91 | href = href.substr(href.lastIndexOf('/') + 1);
92 | return href === '' ? 'index.html' : href;
93 | }
94 |
95 | // Create search form
96 | function createForm(value) {
97 | if ($searchForm) $searchForm.remove();
98 | if ($searchLabel) $searchLabel.remove();
99 | if ($searchInput) $searchInput.remove();
100 |
101 | $searchForm = $('', {
102 | 'class': 'book-search',
103 | 'role': 'search'
104 | });
105 |
106 | $searchLabel = $('