R for Data Science
repository·main·Indexed 26 days ago
https://github.com/hadley/r4dsSource files and build instructions for the R for Data Science book, developed using the Quarto publishing system. Includes guidelines for incorporating Omnigraffle drawings and screenshots, as well as procedures for generating the O'Reilly book version using htmlbook.
What's inside r4ds
- This repository contains the source code for the R for Data Science book. The book is built using Quarto.
Guidelines for including Omnigraffle drawings
mainWhen adding Omnigraffle drawings to the book, follow these specifications to ensure correct scaling and clarity:
- Font: Use 12pt Guardian Sans Condensed or Ubuntu mono.
- Export: Export images as 300 dpi PNG files.
- Scaling: Because the website font is 18px (13.5pt), you must scale the DPI to 270 to match font sizes correctly ($300 \times 12 / 13.5 = 270$).
Use the following knitr configuration to include the graphics:
#| echo: FALSE #| out.width: NULL knitr::include_graphics("diagrams/transform.png", dpi = 270)Guidelines for including Screenshots
mainWhen adding screenshots to the book:
- Theme: Use a light theme.
- Zoom: For small interface elements (e.g., toolbars), zoom in twice before capturing.
- Capture: Use
Cmd + Shift + 4(on macOS). - DPI: Do not set a specific DPI for screenshots.
Use the following knitr configuration to include the screenshots:
#| echo: FALSE #| out.width: NULL knitr::include_graphics("screenshots/rstudio-wg.png")Generate book for O'Reilly
mainTo generate the book version for O'Reilly, first build the book using Quarto, then execute the following R commands to convert and move the files to the target directory (
../r-for-data-science-2e/):- Convert the book using
htmlbook::convert_book(). - Copy all
.htmlfiles from theoreillydirectory to the destination. - Copy all
.pngfiles from theoreillydirectory (recursively) to the destination, ensuring directory structures are created.
# pak::pak("hadley/htmlbook") htmlbook::convert_book() html <- list.files("oreilly", pattern = "[.]html$", full.names = TRUE) file.copy(html, "../r-for-data-science-2e/", overwrite = TRUE) pngs <- list.files("oreilly", pattern = "[.]png$", full.names = TRUE, recursive = TRUE) dest <- gsub("oreilly", "../r-for-data-science-2e/", pngs) fs::dir_create(unique(dirname(dest))) file.copy(pngs, dest, overwrite = TRUE)- Convert the book using