R for Data Science

repository·main·Indexed 26 days ago

https://github.com/hadley/r4ds

Source 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.

Tokens
660
Snippets
3
Records
4
Agent score
40%

What's inside r4ds

  1. Guidelines for including Omnigraffle drawings

    main

    When 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)
  2. Guidelines for including Screenshots

    main

    When 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")
  3. Generate book for O'Reilly

    main

    To 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/):

    1. Convert the book using htmlbook::convert_book().
    2. Copy all .html files from the oreilly directory to the destination.
    3. Copy all .png files from the oreilly directory (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)